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.CloseEnd Sub
(b) Outline the procedure followed in shell sort algorithm in programming. (4 marks)
Answer:
- Divide the array into sublists based on a gap value.
- Sort the sublists using insertion sort.
- Gradually reduce the gap and repeat sorting.
- 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)
- Multiple document interface
- Two-tier interface
Answer:
- Multiple document interface: Allows multiple child windows within a single parent window.
- 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)
- Dim data wide window
- On error
- Option Explicit
Answer:
- Dim: Declares variables.
- On error: Handles runtime errors.
- 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)
- CreateObject()
- SetFocus()
- ReadOnly
Answer:
- CreateObject(): Creates and returns a reference to an object.
- SetFocus(): Sets the focus to a specified control.
- 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:
- Processor speed.
- Available RAM.
- Disk space.
4. (a) Outline four advantages of using bubble sort algorithm in programming. (4 marks)
Answer:
- Simple to implement.
- Requires minimal additional memory.
- Detects sorted data early.
- 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.
- (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
