0% found this document useful (0 votes)
1K views

Chapter 4 Debugging Exercise

The document provides code examples to fix and evaluates variable names for validity. It shows how to properly declare variables as the correct data type, perform calculations using variable values of the appropriate type, and format numeric output strings. Invalid examples are identified and errors are described.

Uploaded by

David Lane
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Chapter 4 Debugging Exercise

The document provides code examples to fix and evaluates variable names for validity. It shows how to properly declare variables as the correct data type, perform calculations using variable values of the appropriate type, and format numeric output strings. Invalid examples are identified and errors are described.

Uploaded by

David Lane
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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