The Kenya National Examinations Council

Diploma in Information Communication Technology

MODULE II – Visual Programming – January 2023

Time: 3 hours

INSTRUCTIONS TO CANDIDATES

  • The paper consists of EIGHT questions.
  • Answer FIVE of the EIGHT questions in the answer booklet provided.
  • Candidates should answer the questions in English.

1. (a) Write a Visual Basic program for the Add button that allows a user to add details from the text boxes to a database table. (6 marks)

Answer:Private Sub cmdAdd_Click()
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset("TableName")
    rs.AddNew
    rs!Field1 = TextBox1.Text
    rs!Field2 = TextBox2.Text
    rs.Update
    rs.Close
End Sub

(b) Outline the procedure followed in shell sort algorithm in programming. (4 marks)

Answer:

  1. Divide the array into sublists based on a gap value.
  2. Sort the sublists using insertion sort.
  3. Gradually reduce the gap and repeat sorting.
  4. Perform a final insertion sort with a gap of one.

(c) Explain each of the following interfaces created in a Visual Basic program: (6 marks)

  1. Multiple document interface
  2. Two-tier interface

Answer:

  1. Multiple document interface: Allows multiple child windows within a single parent window.
  2. Two-tier interface: Consists of client and server layers, allowing communication between them.

2. (a) Differentiate between ActiveX Data Objects (ADO) and Open Database Connectivity (ODBC) as used in a Visual Basic program. (6 marks)

Answer:

  • ADO: Provides a high-level interface for accessing data, supporting various data sources.
  • ODBC: A standard protocol for connecting to different database management systems.

(b) State the function of each of the following instructions in a Visual Basic program: (4 marks)

  1. Dim data wide window
  2. On error
  3. Option Explicit

Answer:

  1. Dim: Declares variables.
  2. On error: Handles runtime errors.
  3. Option Explicit: Requires explicit declaration of all variables.

3. (a) Outline the function of each of the following methods in a Visual Basic program: (6 marks)

  1. CreateObject()
  2. SetFocus()
  3. ReadOnly

Answer:

  1. CreateObject(): Creates and returns a reference to an object.
  2. SetFocus(): Sets the focus to a specified control.
  3. ReadOnly: Allows data to be read but not modified.

(b) State three hardware considerations to be made when installing a Visual Basic program. (6 marks)

Answer:

  1. Processor speed.
  2. Available RAM.
  3. Disk space.

4. (a) Outline four advantages of using bubble sort algorithm in programming. (4 marks)

Answer:

  1. Simple to implement.
  2. Requires minimal additional memory.
  3. Detects sorted data early.
  4. Works well with small datasets.

(b) Differentiate between BOF and EOF recordset object properties ADO command as used in a Visual Basic program. (4 marks)

Answer:

  • BOF (Beginning of File): Indicates the cursor is before the first record.
  • EOF (End of File): Indicates the cursor is after the last record.

(a) Explain each of the following activities carried out during program development in Visual Basic programming: (6 marks)

Compilation
Debugging
Linking
Answer:

Compilation: Converts source code into executable code.
Debugging: Identifies and fixes errors in the program.
Linking: Combines multiple modules into a single executable.
(b) Distinguish between For…next loop and For each…next loop program constructs as used in Visual Basic programming. (6 marks)

Answer:

For…Next loop: Iterates a specific number of times.
For Each…Next loop: Iterates over elements in a collection.

  1. (a) With the aid of an example, outline the function of each of the following operators as used in Visual Basic programs: (6 marks)

And
Or
Mod
Answer:

And: Logical conjunction.
Or: Logical disjunction.
Mod: Remainder of division.
(b) Write a Visual Basic program that prints a sum of squares of integers from 1 to 5 using a Do…While loop and a command button. (6 marks)

Answer:
Private Sub Command1_Click()
Dim i As Integer
Dim sum As Integer
i = 1
Do While i <= 5
sum = sum + (i * i)
i = i + 1
Loop
MsgBox “Sum of squares is ” & sum
End Sub

Leave a Reply