100% found this document useful (1 vote)
230 views4 pages

All 55 Visual Basic Codes FINAL

The document provides Visual Basic code examples for O-Level students, covering various basic programming concepts. Examples include arithmetic operations, finding the largest of two numbers, checking odd or even numbers, a simple login system, calculating the area of a circle, temperature conversion, currency conversion, voting eligibility, generating a multiplication table, and grade checking. Each example includes a brief description and the corresponding code implementation.

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
100% found this document useful (1 vote)
230 views4 pages

All 55 Visual Basic Codes FINAL

The document provides Visual Basic code examples for O-Level students, covering various basic programming concepts. Examples include arithmetic operations, finding the largest of two numbers, checking odd or even numbers, a simple login system, calculating the area of a circle, temperature conversion, currency conversion, voting eligibility, generating a multiplication table, and grade checking. Each example includes a brief description and the corresponding code implementation.

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

4. Simple Login System

Private Sub cmdLogin_Click()


Dim username As String
Dim password As String
username = [Link]
password = [Link]
If username = "admin" And password = "1234" Then
MsgBox "Login Successful"
Else
MsgBox "Invalid credentials"
End If
End Sub

5. Area of a Circle

Private Sub cmdArea_Click()


Dim radius As Double
Dim area As Double
radius = Val([Link])
area = 3.1416 * radius * radius
[Link] = "Area: " & area
End Sub

6. Temperature Converter (Celsius to Fahrenheit)

Private Sub cmdConvert_Click()


Dim celsius As Double
Dim fahrenheit As Double
celsius = Val([Link])
fahrenheit = (celsius * 9 / 5) + 32
[Link] = "Fahrenheit: " & fahrenheit
End Sub
7. Currency Converter

Private Sub cmdConvertCurrency_Click()


Dim usd As Double
usd = Val([Link])
[Link] = "ZWL: " & usd * 1000
End Sub

8. Voting Eligibility

Private Sub cmdCheckAge_Click()


Dim age As Integer
age = Val([Link])
If age >= 18 Then
[Link] = "Eligible to vote"
Else
[Link] = "Not eligible"
End If
End Sub

9. Multiplication Table

Private Sub cmdTable_Click()


Dim num As Integer
Dim i As Integer
num = Val([Link])
[Link]
For i = 1 To 10
[Link] num & " x " & i & " = " & (num * i)
Next i
End Sub

10. Grade Checker

Private Sub cmdCheckGrade_Click()


Dim mark As Integer
mark = Val([Link])
If mark >= 75 Then
[Link] = "A"
ElseIf mark >= 60 Then
[Link] = "B"
ElseIf mark >= 50 Then
[Link] = "C"
ElseIf mark >= 40 Then
[Link] = "D"
Else
[Link] = "F"
End If
End Sub

You might also like