Save Project As Labex1. Using If Then Else Statement, Write A Program in VB That Will Accept A Number

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Alan Carlo C.

Galvez
BSA 4-1

1. Save project as LabEx1. Using If Then Else statement, write a program in VB that will accept a number
value in a TextBox and assign it to a variable and identify if the given number is an odd or even
number.
Public Class Form1
Dim Number As Integer
Private Sub btnevaluate_Click(sender As Object, e As EventArgs) Handles
btnevaluate.Click
Number = txtno.Text
If Number > 0 Then
lblPorN.Text = "Positive"
ElseIf Number < 0 Then
lblPorN.Text = "Negative"
Else
lblPorN.Text = "Neither Positive nor Negative"
End If

If Number Mod 2 = 0 Then


lblOorE.Text = "Even"
Else
lblOorE.Text = "Odd"
End If
End Sub
End Class

2. Save project as LabEx2. Using If Then Else statement, write a program in VB that will accept a character
value in a variable and identify if the given character is vowel or consonant. The program should
identify both capital and small letters.
Public Class Form1
Dim Letter As Char
Private Sub btnevaluate_Click(sender As Object, e As EventArgs) Handles
btnevaluate.Click
Letter = txtLetter.Text
If Letter = "A" Or Letter = "a" Or Letter = "E" Or Letter = "e" Or Letter = "I"
Or Letter = "i" Or Letter = "O" Or Letter = "o" Or Letter = "U" Or Letter = "u" Then
lblVorC.Text = "Vowel"
Else
lblVorC.Text = "Consonant"
End If

End Sub
End Class

3. Save project as LabEx3. Using If Then ElseIf statement, write a program in VB that will assign the value
50,000 to a variable called Amount and a variable that will hold the value for the mode of payment.
The program will then identify the mode of payment. The program will then identify the mode of
payment as the following.

Mode Equivalent
Cash 5% discount
Quarterly 5% interest
Monthly 7% interest

The program will also compute the total amount to be paid according to the mode of payment.

Public Class Form1


Dim Total As Single
Public Const tuition As Single = 50000

Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter

End Sub

Private Sub lblcompute_Click(sender As Object, e As EventArgs) Handles


lblcompute.Click
If rdocash.Checked = True Then
Total = tuition - (tuition * 0.05)
End If
If rdoquarterly.Checked = True Then
Total = tuition + (tuition * 0.05)
End If
If rdomonthly.Checked = True Then
Total = tuition - (tuition * 0.07)
End If
lbltotal.Text = Total
lbltuition.Text = tuition

End Sub
End Class

4. Save project as LabEx4. Using If Then ElseIf statement, write a program in VB that will assign a value in
a variable called VClass and km. The program will then identify the rate and additional fee according to
the following:

Class Rate Additional Fee


1 41 20 per km
2 102 35 per km
3 122 50 per km

The program will also compute the total amount to be paid according to the table above. Formula is
rate + (km * additional fee).
Public Class Form1
Dim kilometer, clas As Single
Private Sub Label2_Click(sender As Object, e As EventArgs) Handles Label2.Click

End Sub

Private Sub btncompute_Click(sender As Object, e As EventArgs) Handles


btncompute.Click
clas = txtclass.Text
kilometer = txtkilometer.Text
If clas = 1 Then
lblrate.Text = 41
lbltotal.Text = txtkilometer.Text * 20 + lblrate.Text
ElseIf clas Then
lblrate.Text = 102
lbltotal.Text = txtkilometer.Text * 35 + lblrate.Text
ElseIf clas = 3 Then
lblrate.Text = 122
lbltotal.Text = txtkilometer.Text * 50 + lblrate.Text
End If

End Sub
End Class

5. Save project as LabEx5. Using If Then ElseIf statement, write a program in VB that will assign values in
ten (10) subjects, the program will then compute for the average of the grade and test according to the
following:

Average Scholarship Grant Tuition Fee Discount


98-100 Presidents List 100%
95-97 College Scholar 50%
92-94 Deans List 30%
91-below None 0

Public Class Form1


Dim sum, average As Single
Dim s1, s2, s3, s4, s5, s6, s7, s8, s9, s10 As Integer

Private Sub Label5_Click(sender As Object, e As EventArgs) Handles Label5.Click

End Sub

Private Sub btncompute_Click(sender As Object, e As EventArgs) Handles


btncompute.Click
s1 = txts1.Text
s2 = txts2.Text
s3 = txts3.Text
s4 = txts4.Text
s5 = txts5.Text
s6 = txts6.Text
s7 = txts7.Text
s8 = txts8.Text
s9 = txts9.Text
s10 = txts10.Text
sum = s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 + s9 + s10
average = sum / 10
lblave.Text = average

End Sub

Private Sub btnclear_Click(sender As Object, e As EventArgs) Handles btnclear.Click


txts1.Text = String.Empty
txts2.Text = String.Empty
txts3.Text = String.Empty
txts4.Text = String.Empty
txts5.Text = String.Empty
txts6.Text = String.Empty
txts7.Text = String.Empty
txts8.Text = String.Empty
txts9.Text = String.Empty
txts10.Text = String.Empty
lblave.Text = String.Empty
txts1.Focus()

End Sub

Private Sub btnview_Click(sender As Object, e As EventArgs) Handles btnview.Click


If average >= 98 And average <= 100 Then
MsgBox("Congratulations you a President's List Scholar and Entitled to 100%
Scholarship", vbOKOnly, "WindowsApplication1")
ElseIf average >= 95 And average <= 97 Then
MsgBox("Congratulations you a College Scholar and Entitled to 50%
Scholarship", vbOKOnly, "WindowsApplication1")
ElseIf average >= 92 And average <= 94 Then
MsgBox("Congratulations you a Dean's List and Entitled to 30% Scholarship",
vbOKOnly, "WindowsApplication1")
Else
MsgBox("Sorry you did not make it this semester..", vbOKOnly,
"WindowsApplication1")
End If
End Sub

End Class
1. Save application as LabSelect1. Using Select Case, write a program in VB that will assign a value in a
noWeek variable and identify the equivalent of the week in number format according to the following:

Days of Week Equivalent


1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday
7 Sunday
Any value not in the range is Invalid Input

Public Class Form1

Dim noWeek As Integer


Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles
txtno.TextChanged

End Sub

Private Sub btnok_Click(sender As Object, e As EventArgs) Handles btnok.Click


noWeek = txtno.Text
Select noWeek
Case 1
MsgBox("Monday", vbOKOnly, "WindowsApplication")
Case 2
MsgBox("Tuesday", vbOKOnly, "WindowsApplication")
Case 3
MsgBox("Wednesday", vbOKOnly, "WindowsApplication")
Case 4
MsgBox("Thursday", vbOKOnly, "WindowsApplication")
Case 5
MsgBox("Friday", vbOKOnly, "WindowsApplication")
Case 6
MsgBox("Saturday", vbOKOnly, "WindowsApplication")
Case 7
MsgBox("Sunday", vbOKOnly, "WindowsApplication")
Case Else
MsgBox("Invalid Input", vbOKOnly, "WindowsApplication")
End Select
End Sub
End Class
2. Save application as LabSelect2. Using Select Case statement, write a program in VB that will assign an
age value in a variable and identify if the age is according to the following:

Age Equivalent
60 - Above Senior Citizen
40 59 Adults
20 - 39 Youth
13 - 19 Teenage
0 12 Kids

Public Class Form1


Dim age As Integer
Private Sub btnok_Click(sender As Object, e As EventArgs) Handles btnok.Click
age = txtage.Text

Select age
Case Is >= 60
MsgBox("Senior Citizen", vbOKOnly, "WindowsApplication")
Case 40 To 59
MsgBox("Adults", vbOKOnly, "WindowsApplication")
Case 20 To 39
MsgBox("Youth", vbOKOnly, "WindowsApplication")
Case 13 To 19
MsgBox("Teenage", vbOKOnly, "WindowsApplication")
Case Is <= 12
MsgBox("Kids", vbOKOnly, "WindowsApplication")

End Select

End Sub

Private Sub txtage_TextChanged(sender As Object, e As EventArgs) Handles


txtage.TextChanged
End Sub
End Class

3. Save application as LabSelect3. Using Select Case Statement, write a program in VB that will assign a
value in a grade variable and identify the equivalent of the grade according to the following:

Grade Equivalent
98 100 1.0
95 97 1.25
92 94 1.50
89 91 1.75
86 88 2.0
83 85 2.25
80 82 2.5
77 79 2.75
75 76 3.0
74 below 5.0

Public Class Form1


Dim Grade As Integer
Private Sub btnok_Click(sender As Object, e As EventArgs) Handles btnok.Click
Grade = txtinput.Text
Select Case Grade
Case 98 To 100
MsgBox(Grade & " = 1.0", vbOKOnly, "WindowsApplication")
Case 95 To 97
MsgBox(Grade & " = 1.25", vbOKOnly, "WindowsApplication")
Case 92 To 94
MsgBox(Grade & " = 1.5", vbOKOnly, "WindowsApplication")
Case 89 To 91
MsgBox(Grade & " = 1.75", vbOKOnly, "WindowsApplication")
Case 86 To 88
MsgBox(Grade & " = 2.0", vbOKOnly, "WindowsApplication")
Case 83 To 85
MsgBox(Grade & " = 2.25", vbOKOnly, "WindowsApplication")
Case 80 To 82
MsgBox(Grade & " = 2.50", vbOKOnly, "WindowsApplication")
Case 77 To 79
MsgBox(Grade & " = 2.75", vbOKOnly, "WindowsApplication")
Case 75 To 76
MsgBox(Grade & " = 3.0", vbOKOnly, "WindowsApplication")
Case Is <= 74
MsgBox(Grade & " = 5.0", vbOKOnly, "WindowsApplication")
End Select

End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub
End Class

4. Save application as LabSelect4. Using Select Case statement, write a program in VB that will assign a
value in a meal, drink, and quantity variables and identify the equivalent according to the following:

Meal Package Price


A Chicken & Spaghetti 150
B Hamburger & Fries 145
C Cheesedog 100
D Pizza 80

Drinks Price
S 30
M 35
L 40
Public Class Form1
Dim quantity, meal, drink As String

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

End Sub

Private Sub btnok_Click(sender As Object, e As EventArgs) Handles btnok.Click


meal = txtmeal.Text
drink = txtdrinks.Text
quantity = txtquantity.Text
Select Case meal
Case "a", "A"
lblorder.Text = "Chicken & Spaghetti"
Select Case drink
Case "s", "S"
lblamount.Text = (150 * quantity) + (30 * quantity)
lblorder.Text = "Chicken & Spaghetti and S drinks"
Case "m", "M"
lblamount.Text = (150 * quantity) + (35 * quantity)
lblorder.Text = "Chicken & Spaghetti and M drinks"
Case "l", "L"
lblamount.Text = (150 * quantity) + (40 * quantity)
lblorder.Text = "Chicken & Spaghetti and L drinks"
End Select
End Select
Select Case meal
Case "b", "B"
lblorder.Text = "Hamburger & Fries"
Select Case drink
Case "s", "S"
lblamount.Text = (145 * quantity) + (30 * quantity)
lblorder.Text = "Hamburger & Fries and S drinks"
Case "m", "M"
lblamount.Text = (145 * quantity) + (35 * quantity)
lblorder.Text = "Hamburger & Fries and M drinks"
Case "l", "L"
lblamount.Text = (145 * quantity) + (40 * quantity)
lblorder.Text = "Hamburger & Fries and L drinks"

End Select
End Select
Select Case meal
Case "c", "C"
lblorder.Text = "Cheesedog"
Select Case drink
Case "s", "S"
lblamount.Text = (100 * quantity) + (30 * quantity)
lblorder.Text = "Cheesedog and S drinks"
Case "m", "M"
lblamount.Text = (100 * quantity) + (35 * quantity)
lblorder.Text = "Cheesedog and M drinks"
Case "l", "L"
lblamount.Text = (100 * quantity) + (40 * quantity)
lblorder.Text = "Cheesedog and L drinks"

End Select
End Select
Select Case meal
Case "d", "D"
lblorder.Text = "Pizza"
Select Case drink
Case "s", "S"
lblamount.Text = (80 * quantity) + (30 * quantity)
lblorder.Text = "Pizza and S drinks"
Case "m", "M"
lblamount.Text = (80 * quantity) + (35 * quantity)
lblorder.Text = "Pizza and M drinks"
Case "l", "L"
lblamount.Text = (80 * quantity) + (40 * quantity)
lblorder.Text = "Pizza and L drinks"
End Select
End Select
End Sub
End Class

5. Save application as LabSelect5. Using Select Case statement, write a program in VB that will assign a
value in a room type, and identify the equivalent according to the following:

Room_Type Equivalent Rate Meal


A Standard 5000 1500
B DeLuxe 15000 2000
C Suite 20000 3000

Code Payment Equivalent


1 Cash 2% discount
2 Credit Card 5% Interest

Public Class Form1


Dim Room, Code As Char
Dim Amount, Discount, Rate, Meal As Integer

Private Sub btnok_Click(sender As Object, e As EventArgs) Handles btnok.Click


Room = txtRoom.Text

Select Case Room


Case "A", "a"
lblequivalent.Text = "Standard"
lblrate.Text = 5000
lblmeal.Text = 1500
Case "B", "b"
lblequivalent.Text = "DeLuxe"
lblrate.Text = 15000
lblmeal.Text = 2000
Case "C", "c"
lblequivalent.Text = "Suite"
lblrate.Text = 20000
lblmeal.Text = 3000
End Select

Rate = lblrate.Text
Meal = lblmeal.Text
Code = txtCode.Text

Select Code
Case "1"
lblpayment.Text = "Cash"
Discount = (Rate + Meal) * 0.02
Amount = (Rate + Meal) - Discount
Case "2"
lblpayment.Text = "Credit Cash"
Discount = (Rate + Meal) * 0.05
Amount = (Rate + Meal) + Discount
End Select
lbldiscount.Text = Discount
lbltotal.Text = Amount

End Sub
End Class

You might also like