Examlex
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
Social Traps
Situations where individuals or groups pursue immediate rewards that later prove to have negative or even disastrous consequences.
Overconfidence
The psychological state of being too confident in one’s own abilities, often leading to taking greater risks.
Recycling
The process of converting waste materials into new materials and objects, aiming to reduce consumption of fresh raw materials, energy usage, and environmental pollution.
Commons Dilemmas
A situation where individual interests conflict with the collective interest, often resulting in the overuse or degradation of a common resource.
Q4: Use the _ flowchart symbol to represent
Q7: Text that cannot be changed by the
Q9: An independent Sub procedure is a procedure
Q14: What is a constructor? Explain the difference
Q20: A named constant's value cannot be changed
Q21: Which of the following statements declares a
Q41: What is a nested selection structure? How
Q43: Case-Based Critical Thinking Questions Case 1 -
Q48: To remove characters from the left of,
Q53: Writing LINQ Statements <br>The tblBicycle table contains