ZIMSEC O'LEVEL
VISUAL BASIC PROGRAMMING
BOOKLET
Form 1–4 Revision • Programming & Practical Exam Preparation
Computer Science 4021 • Beginner → Exam Level
Prepared as a revision guide aligned to the programming emphasis of the ZIMSEC Computer Science practical examination.
ZIMSEC O-Level Visual Basic Programming Booklet
Page 1
Contents
1. Introduction to Visual Basic
2. Forms and Controls
3. Variables and Data Types
4. Input and Output
5. Operators and Calculations
6. Selection: If and Select Case
7. Loops
8. Arrays
9. Procedures and Functions
10. Strings and Validation
11. Random Numbers
12. Console Programming
13. Algorithms, Flowcharts and Trace Tables
14. ZIMSEC-Style Practical Questions
15. Exam Checklist
16. Quick Syntax Sheet
ZIMSEC O-Level Visual Basic Programming Booklet
Page 2
1. Introduction to Visual Basic
Visual Basic (VB) is a programming language used to create applications with graphical user interfaces (GUIs). A
VB program commonly uses a Form containing controls such as labels, text boxes and buttons.
Key idea: an event is an action such as clicking a button. Code attached to that event runs when the event occurs.
Common terms: Form = window/interface; Control = object placed on a form; Property = characteristic such as Text
or Name; Event = action such as Click; Procedure = block of code that performs a task.
2. Forms and Controls
Important controls: Label displays text; TextBox accepts input; Button starts an action; ListBox displays a list;
ComboBox provides a drop-down list; CheckBox allows yes/no or multiple choices; RadioButton selects one option
from a group.
Useful properties include Name, Text, Enabled, Visible, Font and BackColor. Give controls meaningful names such
as txtName, lblResult and btnCalculate.
Good interface design: clear labels, sensible alignment, readable text, obvious buttons and useful validation.
3. Variables and Data Types
A variable stores a value that can change while a program runs. Common types include Integer, Double, Decimal,
String, Char and Boolean.
Declaration example:
Dim age As Integer
Dim name As String
Dim price As Decimal
Dim passed As Boolean
Use the correct data type. Text should normally be String; whole numbers Integer; numbers requiring decimals
Double or Decimal; true/false Boolean.
4. Input and Output
TextBox input is usually read through its Text property. Output can be placed in a Label or displayed with MsgBox.
Example:
Dim name As String
name = txtName.Text
lblOutput.Text = "Hello " & name
InputBox can also request input:
Dim name As String
name = InputBox("Enter your name")
MsgBox("Hello " & name)
5. Operators and Calculations
Arithmetic operators: + addition, - subtraction, * multiplication, / division, \ integer division, Mod remainder, ^ power.
Relational operators: =, <>, <, >, <=, >=. Logical operators include And, Or and Not.
ZIMSEC O-Level Visual Basic Programming Booklet
Page 3
Example:
Dim total As Decimal
total = Val(txtPrice.Text) * Val(txtQuantity.Text)
lblTotal.Text = total.ToString()
Exam tip: show the formula clearly and convert text input to a numeric type before calculating.
6. Selection: If and Select Case
Selection allows a program to make decisions.
Basic If:
If mark >= 50 Then
lblResult.Text = "PASS"
Else
lblResult.Text = "FAIL"
End If
Nested decision:
If mark >= 75 Then
grade = "A"
ElseIf mark >= 60 Then
grade = "B"
ElseIf mark >= 50 Then
grade = "C"
Else
grade = "F"
End If
Select Case is useful when one value has several possible cases:
Select Case choice
Case 1
lblResult.Text = "Add"
Case 2
lblResult.Text = "Subtract"
Case Else
lblResult.Text = "Invalid choice"
End Select
ZIMSEC O-Level Visual Basic Programming Booklet
Page 4
7. Loops
Loops repeat instructions. For...Next is useful when the number of repetitions is known. Do While repeats while a
condition remains true.
For loop:
Dim i As Integer
For i = 1 To 10
ListBox1.Items.Add(i)
Next
Do While:
Dim n As Integer
n = 1
Do While n <= 5
ListBox1.Items.Add(n)
n += 1
Loop
Always make sure a loop can eventually stop; otherwise you may create an infinite loop.
8. Arrays
An array stores multiple values under one variable name. An indexed array is useful for lists of marks, prices or
names.
Example:
Dim marks(4) As Integer
marks(0) = 45
marks(1) = 67
marks(2) = 72
marks(3) = 51
marks(4) = 80
For i = 0 To 4
ListBox1.Items.Add(marks(i))
Next
Remember that the index of the first element is commonly 0 in VB arrays.
9. Procedures and Functions
A Sub procedure performs a task. A Function performs a task and returns a value.
Sub example:
Sub ShowMessage()
MsgBox("Welcome")
End Sub
Function example:
Function Square(ByVal n As Integer) As Integer
Return n * n
End Function
Use procedures/functions to reduce repeated code and make programs easier to test.
ZIMSEC O-Level Visual Basic Programming Booklet
Page 5
10. Strings and Validation
String operations include concatenation with &, checking Length, and extracting parts with methods such as
Substring.
Validation means checking whether input is acceptable before processing it.
Example:
If txtName.Text = "" Then
MsgBox("Enter your name")
Else
lblResult.Text = "Welcome " & txtName.Text
End If
Numeric validation can also check ranges, for example 0 <= mark <= 100.
11. Random Numbers
Random numbers are useful for dice, games and simulations.
Example:
Dim rnd As New Random()
Dim number As Integer
number = rnd.Next(1, 7)
lblResult.Text = number.ToString()
Note: Next(1, 7) produces values from 1 through 6 because the upper limit is excluded.
12. Console Programming
Console programs use text input/output rather than a graphical form. The basic tools are Console.WriteLine,
Console.Write and Console.ReadLine.
Example:
Module Program
Sub Main()
Dim name As String
Console.Write("Enter your name: ")
name = Console.ReadLine()
Console.WriteLine("Hello " & name)
Console.ReadLine()
End Sub
End Module
Numeric input:
Dim age As Integer
Console.Write("Enter age: ")
age = Integer.Parse(Console.ReadLine())
If age >= 18 Then
Console.WriteLine("Adult")
Else
Console.WriteLine("Minor")
End If
Console exam habit: identify input, processing and output before writing code.
ZIMSEC O-Level Visual Basic Programming Booklet
Page 6
13. Algorithms, Flowcharts and Trace Tables
An algorithm is a finite sequence of steps for solving a problem. A flowchart represents an algorithm graphically.
Common flowchart symbols: oval = Start/End; parallelogram = Input/Output; rectangle = Process; diamond =
Decision.
Trace tables record variable values as a program executes. They are useful for loops and decisions.
IPO method: Input → Processing → Output. Example for area: input length and width → multiply them → display
area.
14. ZIMSEC-Style Practical Questions
The ZIMSEC Computer Science practical specimen identifies Programming as a major section of Paper 3. The
specimen includes tasks such as designing an interface, writing code to greet a user, generating a random number,
displaying a pattern and determining whether a number is even. The current 2026 specimen is listed as 4021/3.
■cite■turn0search13■
Practice 1 — Greeting: Design an interface that accepts a name and displays “Hello [name]”.
Practice 2 — Even/Odd: Input a number and display whether it is even or odd.
Practice 3 — Random number: Generate a random integer from 1 to 6.
Practice 4 — Pattern: Use nested loops to display a 5 by 5 pattern.
Practice 5 — Age: Input age and display an appropriate message.
Practice 6 — Calculator: Input two numbers and a choice, then perform the selected operation.
Practical presentation matters: the specimen instructs candidates to indicate the software used, print
answers/screenshots and submit hard and soft copies. ■cite■turn0search1■turn0search6■
ZIMSEC O-Level Visual Basic Programming Booklet
Page 7
15. Exam Checklist
Before submitting a practical program, check: interface is complete; controls have sensible names; code is saved;
inputs are tested; boundary values are tested; outputs are readable; no unnecessary errors appear;
screenshots/printouts are included where required; files are saved in the required location.
Test cases should include normal values, boundary values and invalid values.
Typical boundary examples: 49/50 for a pass mark of 50; 12/13 for an age limit of 13; 1/6 for a dice range.
16. Quick Syntax Sheet
Declare: Dim x As Integer
String input: name = txtName.Text
Message: MsgBox("Hello")
Label output: lblResult.Text = "Done"
Conversion: Val(text), Integer.Parse(text)
Decision: If condition Then ... Else ... End If
Multiple decisions: ElseIf
Selection: Select Case value ... Case ... End Select
Loop: For i = 1 To 10 ... Next
While loop: Do While condition ... Loop
Array: Dim marks(9) As Integer
Random 1–6: rnd.Next(1, 7)
Console output: Console.WriteLine("Hello")
Console input: Console.ReadLine()
ZIMSEC O-Level Visual Basic Programming Booklet
Page 8
Practice Answers — Selected
Even/Odd:
Dim n As Integer
n = Val(txtNumber.Text)
If n Mod 2 = 0 Then
lblResult.Text = "Even"
Else
lblResult.Text = "Odd"
End If
5 × 5 pattern:
For row = 1 To 5
For col = 1 To 5
Console.Write("# ")
Next
Console.WriteLine()
Next
Simple calculator:
Dim a As Double = Val(txtA.Text)
Dim b As Double = Val(txtB.Text)
Dim answer As Double
answer = a + b
lblAnswer.Text = answer.ToString()
Final revision advice: practise writing the program from the problem statement, not by memorising one exact
program. ZIMSEC practical questions can change the story while testing the same programming skills.
ZIMSEC O-Level Visual Basic Programming Booklet
Page 9