0% found this document useful (0 votes)
78 views5 pages

Chapter Four Exercises

The document contains 9 coding exercises demonstrating the use of conditional statements like If/ElseIf/Else and logical operators in Visual Basic.NET. Each exercise shows how to use conditional logic to evaluate inputs, calculate outputs, and return messages based on the input values and conditions. The exercises cover tasks like number validation, wage calculation, price determination, package approval, computer troubleshooting, defect detection, grade tracking, fee calculation, and login validation.

Uploaded by

api-307933836
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)
78 views5 pages

Chapter Four Exercises

The document contains 9 coding exercises demonstrating the use of conditional statements like If/ElseIf/Else and logical operators in Visual Basic.NET. Each exercise shows how to use conditional logic to evaluate inputs, calculate outputs, and return messages based on the input values and conditions. The exercises cover tasks like number validation, wage calculation, price determination, package approval, computer troubleshooting, defect detection, grade tracking, fee calculation, and login validation.

Uploaded by

api-307933836
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
You are on page 1/ 5

Exercise 1

Public Class Form1


Dim Number As Double
Private Sub btnAnswer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnAnswer.Click
Number = txtboxNum.Text
If txtboxNum.Text < 10 Then
lblMessage.Text = "The number is a one digit number"
ElseIf txtboxNum.Text > 99 Then
lblMessage.Text = "Invalid number"
Else : lblMessage.Text = "The number is a two digit number"
End If
End Sub
End Class

Exercise 2
Public Class Form1
Dim Hours As Double
Dim Rate As Double
Private Sub btnPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnPay.Click
Hours = txtHours.Text
Rate = txtRate.Text
If radbtnYes.Checked = True Then
lblWage.Text = Hours * Rate
txtTaxes.Text = "No taxes deducted"
Else
lblWage.Text = (Hours * Rate) - ((Hours * Rate) * 0.18)
txtTaxes.Text = ""
End If
End Sub
End Class

Exercise 3
Public Class Form1
Dim Amount As Double
Private Sub btnPrice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnPrice.Click
Amount = txtboxAmount.Text
If txtboxAmount.Text < 500 Then
lblPrice.Text = "$0.30"
lblTotal.Text = 0.3 * Amount

ElseIf txtboxAmount.Text > 499 And txtboxAmount.Text < 750 Then


lblPrice.Text = "$0.28"
lblTotal.Text = 0.28 * Amount
ElseIf txtboxAmount.Text > 749 And txtboxAmount.Text < 1000 Then
lblPrice.Text = "$0.27"
lblTotal.Text = 0.27 * Amount
ElseIf txtboxAmount.Text > 999 Then
lblPrice.Text = "$0.25"
lblTotal.Text = 0.25 * Amount
End If
End Sub
End Class

Exercise 4
Public Class Form1
Dim Shape As Double
Private Sub btnPackage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnPackage.Click
Shape = txtboxHeight.Text * txtboxLength.Text * txtboxWidth.Text
If txtboxWeight.Text < 28 And Shape < 100000 Then
lblAnswer.Text = "Approved"
ElseIf txtboxWeight.Text > 27 And Shape < 100000 Then
lblAnswer.Text = "Rejected: Too Heavy"
ElseIf txtboxWeight.Text < 28 And Shape > 100000 Then
lblAnswer.Text = "Rejected: Too Large"
ElseIf txtboxWeight.Text > 27 And Shape > 100000 Then
lblAnswer.Text = "Rejected: Too Heavy and too Large"
End If
End Sub
End Class

Exercise 5
Public Class Form1
Private Sub btnAnswer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnAnswer.Click
If txtboxBeep.Text.Equals("Y") And txtboxDrive.Text.Equals("Y") Then
lblAnswer.Text = "Contact tech support"
ElseIf txtboxBeep.Text.Equals("Y") And txtboxDrive.Text.Equals("N") Then
lblAnswer.Text = "Check drive contacts"

ElseIf txtboxBeep.Text.Equals("N") And txtboxDrive.Text.Equals("Y") Then


lblAnswer.Text = "Check the speaker connections"
ElseIf txtboxBeep.Text.Equals("N") And txtboxDrive.Text.Equals("N") Then
lblAnswer.Text = "Bring computer to repair center"
End If
End Sub
End Class

Exercise 6
Public Class Form1
Private Sub btnAnswer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnAnswer.Click
If txtboxModel.Text = 119 Or
txtboxModel.Text = 179 Or txtboxModel.Text = 189 Or
txtboxModel.Text = 190 Or txtboxModel.Text = 191 Or
txtboxModel.Text = 192 Or txtboxModel.Text = 193 Or
txtboxModel.Text = 194 Or txtboxModel.Text = 195 Or
txtboxModel.Text = 221 Or txtboxModel.Text = 780 Then
lblAnswer.Text = "Your car is defective. Please have it fixed"
Else
lblAnswer.Text = "Your car is not defective"
End If
End Sub
End Class

Exercise 7
Public Class Form1
Dim Pass As Double
Dim Fail As Double
Private Sub btnGrade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnGrade.Click
lblFailed.Text = Fail
lblPassed.Text = Pass
If txtboxGrade.Text.Equals("A") Or txtboxGrade.Text.Equals("a") Or
txtboxGrade.Text.Equals("B") Or txtboxGrade.Text.Equals("b") Or
txtboxGrade.Text.Equals("C") Or txtboxGrade.Text.Equals("c") Or
txtboxGrade.Text.Equals("D") Or txtboxGrade.Text.Equals("d") Then
Pass = Pass + 1
ElseIf txtboxGrade.Text.Equals("F") Or txtboxGrade.Text.Equals("f") Then
Fail = Fail + 1
End If
End Sub
End Class

Exercise 8
Public Class Form1
Dim Wait As Double
Dim Forward As Double
Dim ID As Double
Private Sub chkboxWait_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles chkboxWait.CheckedChanged
Wait = 3.5
End Sub
Private Sub chkboxForward_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles chkboxForward.CheckedChanged
Forward = 3.5
End Sub
Private Sub chkboxID_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles chkboxID.CheckedChanged
ID = 3.5
End Sub
Private Sub btnAnswer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnAnswer.Click
lblTotal.Text = 25.0 + Wait + Forward + ID
End Sub
End Class

Exercise 9
Public Class Form1
Dim Denied As Double
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Application.Exit()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
If txtboxUser.Text = "Username" And txtboxPass.Text = "Password" Then
MessageBox.Show("The ID and Password are correct.", "", _
MessageBoxButtons.OK)
Application.Exit()
ElseIf txtboxUser.Text = "Username" And txtboxPass.Text <> "Password" Then
MessageBox.Show("Incorrect Password", "", _
MessageBoxButtons.OK)
Denied = Denied + 1
txtboxPass.Text = ""
ElseIf txtboxUser.Text <> "Username" And txtboxPass.Text = "Password" Then
MessageBox.Show("Incorrect ID", "", _

MessageBoxButtons.OK)
Denied = Denied + 1
txtboxUser.Text = ""
ElseIf txtboxUser.Text <> "Username" And txtboxPass.Text <> "Password" Then
MessageBox.Show("Incorrect ID and Password", "", _
MessageBoxButtons.OK)
Denied = Denied + 1
txtboxUser.Text = ""
txtboxPass.Text = ""
End If
If Denied = 3 Then
MessageBox.Show("Sorry, access denied.", "", _
MessageBoxButtons.OK)
Application.Exit()
End If
End Sub
End Class

You might also like