Problems - Correcting Logic and Code Errors
The following sample of code contains errors. Rewrite the incorrect statements to correct all errors.
Private Sub btnDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDisplay.Click
' displays type of vehicle for the code entered by user
Const strLENGTH_MSG As String = "The code must contain four characters."
Const strTYPE_MSG As String = "The last character in the code must be C, T, or V."
Dim strCode As String
Dim strLastChar As String
strCode = txtCode.Text.ToLower
' determine whether code contains exactly 4 characters
If strCode.Chars
lblType.Text = String.Empty
MessageBox.Show(strLENGTH_MSG, "Code",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
' determine whether the last character is valid
strLastChar = strCode.Substring(4)
Select Case strCode
Case "C"
lblType.Text = "Car"
Case "T"
lblType.Text = "Truck"
Case "V"
lblType.Text = "Van"
Case Else
lblType.Text = String.Empty
MessageBox.Show(strType_MSG, "Type",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
End If
End If
End Sub
Correct Answer:
Verified
View Answer
Unlock this answer now
Get Access to more Verified Answers free of charge
Q41: The strSerialNum variable contains the string "DRY259614".Write
Q42: What is the difference between a menu
Q43: Case-Based Critical Thinking Questions Case 1 -
Q44: Write the Visual Basic statement that inserts
Q46: Write the condition that evaluates to True
Q47: The txtGrade control contains the string "95%".Write
Q49: Case-Based Critical Thinking Questions Case 1 -
Q51: Case-Based Critical Thinking Questions Case 1 -
Q51: The strPhone variable contains a 10-digit phone
Q57: Describe four of the six menu standards
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents