Problems: Correcting Logic and Code ErrorsThe 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 userConst 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 StringDim strLastChar As StringstrCode = txtCode.Text.ToLower' determine whether code contains exactly 4 charactersIf strCode.Chars < 4 ThenlblType.Text = String.EmptyMessageBox.Show(strLENGTH_MSG, "Code",MessageBoxButtons.OK,MessageBoxIcon.Information)Else' determine whether the last character is validstrLastChar = strCode.Substring(4)Select Case strCodeCase "C"lblType.Text = "Car"Case "T"lblType.Text = "Truck"Case "V"lblType.Text = "Van"Case ElselblType.Text = String.EmptyMessageBox.Show(strType_MSG, "Type",MessageBoxButtons.OK,MessageBoxIcon.Information)End IfEnd IfEnd Sub

What will be an ideal response?


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.ToUpper

' determine whether code contains exactly 4 characters
If strCode.Length<> 4 Then
lblType.Text = String.Empty
MessageBox.Show(strLENGTH_MSG, "Code",
MessageBoxButtons.OK,
MessageBoxIcon.Information)
Else
' determine whether the last character is valid
strLastChar = strCode.Substring(3)
Select Case strLastChar
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

Computer Science & Information Technology

You might also like to view...

Static class variables:

a. are final. b. are public. c. are private. d. are shared by all objects of a class.

Computer Science & Information Technology

A common use of the type of list in the accompanying figure is to create a(n) ____________________, which is an alphabetic list of terms and their definitions.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

You can use ________ in conjunction with data in existing columns to separate the data into distinct columns

A) Format Painter B) the fill handle C) Flash Fill D) Copy with Paste Special

Computer Science & Information Technology

What should you do if your dot-matrix printer output is covered with dots and small smudges?

A. Replace the drum. B. Clean the platen. C. Clean the printhead. D. Replace the cartridge.

Computer Science & Information Technology