Visual Basic Source Codes for Class 11 HSc Paper 1 Practicals
1. Narayana Junior College, Kalyan
XI Computer Science
Mentor: Aditi Bhushan
Visual Basic Practical
Q1. Write a V.B. Program to find grade (H, I, II, III, F) from marks given by user.
Output:
Program:
Private Sub Command1_Click()
Dim m, p, c, total As Integer
Dim result As Long
m = Val(Text1.Text)
p = Val(Text2.Text)
c = Val(Text3.Text)
total = m + p + c
result = (total / 3)
If (result > 70) Then
Label4.Caption = "H Grade"
ElseIf (result < 70 And result > 60) Then
Label4.Caption = "I Grade"
ElseIf (result < 60 And result > 50) Then
2. Narayana Junior College, Kalyan
XI Computer Science
Label4.Caption = "II Grade"
ElseIf (result < 40 And result > 50) Then
Label4.Caption = "III Grade"
Else
Label4.Caption = "F Grade, Fail"
Label4.Font.Size = 20
End If
End Sub
Q.2. Write a V.B. program to find whether a number given is prime or not.
Output:
Program:
Private Sub Command1_Click()
Dim i, x As Integer
x = Val(Text1.Text)
For i = 2 To x - 1
If (x Mod i = 0) Then
Label2.Caption = Text1.Text + " is not a prime no."
3. Narayana Junior College, Kalyan
XI Computer Science
Exit For
End If
Next i
If i = x Then
Label2.Caption = Text1.Text + " is a PRIME no."
End If
End Sub
Q.3. Calculate area of triangle in V.B.
Private Sub Command1_Click()
Dim a, b, c As Integer
Dim area As Long
a = Val(Text1.Text)
b = Val(Text2.Text)
area = 0.5 * a * b
Label3.Caption = area
End Sub
PAGE 119, Q.3.
4. Narayana Junior College, Kalyan
XI Computer Science
Private Sub Command1_Click()
Dim over, run As Integer
Dim runrate As Long
over = Text1.Text
run = Text2.Text
If (over < 50) Then
runrate = run / over
Text3.Text = runrate
Else
Label4.Caption = "Over Cannot exceed 50"
End If
End Sub
Private Sub Command2_Click()
End
End Sub