Chapter 4 Debugging Exercise

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

1.

Fix the following code:

Option Strict On Dim intDistance As Integer intDistance = 17.5 o Option strict On Public Class Form1 Const _cintDistance As Integer = 17.5I End Class

2. Fix the following code:

Dim dblRegularPay As Double Dim dblOvertimePay As Double intRegularPay = 783.87 intOvertimePay = 105.92 lbl.TotalPay = (dblRegularPay + dblOvertimePay).ToString('C') o Dim dblRegularPay As Double Dim dblOvertimePay As Double dblRegularPay = 783.87 dblOvertimePay = 105.92 dblTotalPay = (dblRegularPay + dblOvertimePay) lblTotalPay.Text = dblTotalPay.ToString("C")

3. Determine if each of the following variable names is valid or invalid. Please state the error in the invalid variable names.

Public Class Form1 Private Sub btnCalculate_Click Dim strLengthOfSide As String o Valid Dim intArea As Integer
o

Valid

strLengthOfSide = txtLengthOfSide.text

Valid

intArea = strLengthOfSide ^ 2
o

Invalid - strLengthOfSide must be converted to a numeric value before an arithmetic operation can be completed

lblArea.text = intArea.ToString("C")
o

Invalid - The ToString format specification is set to currency ("C") which does not fit with the data type integer being used, in this case a straight () or Number ("N") conversion would be best for the data return formatting.

End Sub End Class

You might also like