0% found this document useful (0 votes)
14 views2 pages

Visual Basic Code Examples for O-Level

The document provides Visual Basic code examples for O-Level students, focusing on basic arithmetic operations, finding the largest of two numbers, and checking if a number is odd or even. Each example includes a subroutine that performs the specified task and updates the user interface with the results. These examples serve as practical exercises for students to learn programming concepts in Visual Basic.

Uploaded by

tadiwarrr.88
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Visual Basic Code Examples for O-Level

The document provides Visual Basic code examples for O-Level students, focusing on basic arithmetic operations, finding the largest of two numbers, and checking if a number is odd or even. Each example includes a subroutine that performs the specified task and updates the user interface with the results. These examples serve as practical exercises for students to learn programming concepts in Visual Basic.

Uploaded by

tadiwarrr.88
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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([Link])
num2 = Val([Link])
[Link] = "Sum: " & (num1 + num2)
[Link] = "Difference: " & (num1 - num2)
[Link] = "Product: " & (num1 * num2)
[Link] = "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([Link])
b = Val([Link])
If a > b Then
[Link] = "A is greater"
ElseIf b > a Then
[Link] = "B is greater"
Else
[Link] = "Both are equal"
End If
End Sub

3. Odd or Even Checker

Private Sub cmdCheck_Click()


Dim num As Integer
num = Val([Link])
If num Mod 2 = 0 Then
[Link] = "Even Number"
Else
[Link] = "Odd Number"
End If
End Sub

You might also like