' Visual Basic Code Examples for O-Level Students
' 1. Basic Arithmetic Operations
Private Sub cmdCalculate_Click()
Dim num1 As Double
Dim num2 As Double
num1 = Val(txtNum1.Text)
num2 = Val(txtNum2.Text)
lblAdd.Caption = "Sum: " & (num1 + num2)
lblSub.Caption = "Difference: " & (num1 - num2)
lblMul.Caption = "Product: " & (num1 * num2)
lblDiv.Caption = "Quotient: " & (num1 / num2)
End Sub
' 2. Find the Largest of Two Numbers
Private Sub cmdCompare_Click()
Dim a As Integer
Dim b As Integer
a = Val(txtA.Text)
b = Val(txtB.Text)
If a > b Then
lblResult.Caption = "A is greater"
ElseIf b > a Then
lblResult.Caption = "B is greater"
Else
lblResult.Caption = "Both are equal"
End If
End Sub
' 3. Odd or Even Checker
Private Sub cmdCheck_Click()
Dim num As Integer
num = Val(txtNumber.Text)
If num Mod 2 = 0 Then
lblResult.Caption = "Even Number"
Else
lblResult.Caption = "Odd Number"
End If
End Sub
' ... (Programs 4 to 55 skipped here due to space; they'll be included below)