0% found this document useful (0 votes)
2 views

Ch-9 Programming

The document contains a series of Visual Basic (VB) programs that demonstrate sequential and conditional programming concepts. It includes code examples for calculating the area of a rectangle, distance, square and cube of a number, and checking voting eligibility, odd/even status, divisibility, and percentage remarks. Each program is triggered by a button click and utilizes text boxes for user input and output display.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Ch-9 Programming

The document contains a series of Visual Basic (VB) programs that demonstrate sequential and conditional programming concepts. It includes code examples for calculating the area of a rectangle, distance, square and cube of a number, and checking voting eligibility, odd/even status, divisibility, and percentage remarks. Each program is triggered by a button click and utilizes text boxes for user input and output display.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

10.1.

2025

Ch-9

Sequential Programs:

Program 1. WAP a program in VB to accept the length and breadth from the user through the text
boxes. Calculate the area of rectangle and display in 3rd textbox on click of a button"Calculate Area".

Private Sub Command1_Click()

Dim L, B, Ar As Integer

L = Val(Text1.Text)

B = Val(Text2.Text)

Ar = L * B

Text3.Text = Ar

End Sub

Program 2.WAP to accept a value of speed and time from the user.Calculate the distance covered and
show the output in the 3rd text box on the click of a button "Calculate Distance".

Private Sub Command1_Click()

Dim S, T, Dis As Integer

S = Val(Text1.Text)

T = Val(Text2.Text)

Dis = S * T

Text3.Text = Dis

End Sub
Program 3. WAP to accept a number in the 1st textbox. Claculate the square and cube of the same
number in 2nd and 3rd textboxes respectively on the click of a button "Calculate".

Private Sub Command1_Click()

Dim N, S, C As Integer

N = Val(Text1.Text)

S=N^2

C=N^3

Text2.Text = S

Text3.Text = C

End Sub

***************************************************************************

Conditional Programs:

**Syntax for Conditional Programming:**

1.If condition

If (Condition) Then

----------

--------- true case

---------

End If

2. If Then ………..Else

If (Condition ) Then
--------- True case

--------

Else

---------

-------- false case

End If

3.If Then…………ElseIf

If (Cond1) Then

--------------

ElseIf(Cond2) Then

-----------------

ElseIf(Cond3) Then

------------------

Else

-----------------

End If

*****************************************************************

Program 4. WAP to accept the age from the user in 1st text box. Check his eligibility for voting on the
click of a button “Check”.

Private Sub Command1_Click()

Dim Age As Integer

Age = Val(Text1.Text)

If (Age >= 18) Then

MsgBox ("You can vote")

Else

MsgBox ("You can't Vote")


End If

End Sub

Program 5. WAP to accept a number from the user through textbox. Check whether the number is odd
or even on the click of a button “Check”.

Private Sub Command1_Click()

Dim N As Integer

N = Val(Text1.Text)

If (N Mod 2 = 0) Then

MsgBox ("Even Number")

Else

MsgBox ("Odd Number")

End If

End Sub

Program 6. WAP to accept a number from the user through textbox. Check whether the number is
divisible by both 2 and 5 on the click of a button “Check”.

Private Sub Command1_Click()

Dim N As Integer

N = Val(Text1.Text)

If ((N Mod 2 = 0) And (N Mod 5 = 0)) Then

MsgBox ("Number is divisible by 2 and 5 both")

Else

MsgBox ("Number is not divisible by 2 and 5 both")

End If

End Sub

Program 7. WAP to accept percentage from the user through text box and show the remarks in
message box based on the following criteria.

Percent<40: “Failed”
Percent>=40 and <50 “Passed”

Percent>=50 and <60 “Average”

Percent>=60 and <80 “Good”

Percent>=80 “Very Good”

Private Sub Command1_Click()

Dim P As Single

P = Val(Text1.Text)

If (P >= 80) Then

MsgBox ("Very Good")

ElseIf (P >= 60) Then

MsgBox ("Good")

ElseIf (P >= 50) Then

MsgBox ("Average")

ElseIf (P >= 40) Then

MsgBox ("Passed")

Else

MsgBox ("Failed")

End If

End Sub

You might also like