The Kenya National Examinations Council

Diploma in Information Communication Technology

MODULE II – Visual Programming – November 2022

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) Distinguish between Do…While…Loop and Do…Loop…While statements as used in Visual Basic programs. Give examples in each case. (6 marks)

  • Do…While…Loop: Executes as long as the condition is true at the start.
  • Do…Loop…While: Executes at least once and then checks the condition at the end.

(b) The vertical height (h) in meters of a particle projected vertically upwards with an initial velocity (u) m/s at any given time (t) s is obtained using the formula h = ut – 4.9t². Write a Visual Basic program that uses the program to determine the height of a particle from the time it is projected up to the time it returns to the same starting point. The program should plot a graph that shows the height of the particle with respect to time. Attach the code to a command button. (8 marks)

  • Answer:
vbCopy codePrivate Sub Command1_Click()
    Dim t As Single
    Dim u As Single
    Dim h As Single
    u = Val(Text1.Text)
    For t = 0 To (2 * u / 9.8) Step 0.1
        h = u * t - 4.9 * t * t
        ' Code to plot graph using h and t values
    Next t
End Sub

(c) Outline four methods used in forms in Visual Basic programs. (4 marks)

  1. Show
  2. Hide
  3. Load
  4. Unload

2. (a) State the Visual Basic type conversion functions used to convert a string into each of the following types of data. (6 marks)

  1. Boolean data: CBool()
  2. Currency data: CCur()
  3. Date data: CDate()
  4. Integer data: CInt()

(b) State a circumstance that necessitates the use of each of the following statements in Visual Basic programs. (4 marks)

  1. Option Explicit: When you want to enforce explicit variable declarations.
  2. With…End With: When you need to perform multiple operations on the same object or structure.

3. (a) Explain the function of each of the following statements used in error trapping in a Visual Basic program. (6 marks)

  1. On Error GoTo line: Redirects code execution to a specific line if an error occurs.
  2. On Error Resume Next: Ignores the error and continues with the next line of code.
  3. On Error Resume 0: Disables any enabled error handler.

4. (a) Write a Visual Basic program that would accept a character through the use of a text box, then display the character along with its equivalent color code. (6 marks)

  • Answer:
vbCopy codePrivate Sub Command1_Click()
    Dim char As String
    char = Text1.Text
    Select Case char
        Case "R": Label1.BackColor = vbRed
        Case "G": Label1.BackColor = vbGreen
        Case "B": Label1.BackColor = vbBlue
        ' Add more cases as needed
    End Select
    Label1.Caption = char
End Sub

5. (a) Differentiate between an argument and a parameter as used in Visual Basic programs. (4 marks)

  • Argument: The actual value passed to a procedure.
  • Parameter: The variable that holds the argument value inside the procedure

Leave a Reply