Thursday, October 8, 2009

Code Structure - Must Read


The following is a code snippet from the click event of the calculate button (Assignment 5-4). Please make sure your code has the following 3 steps. Note, The computer executes code sequentially, so these steps must be in the order specified.


1. Move form objects into variables ( otherwise your variables will contain nothing)

2. Processing (All of the calculations)

3. Move the output variable into form object. ( otherwise the labels will display nothing)


Const cIntSingle As Integer = 38I
Const cIntFamily As Integer = 58I
Const cintAncient As Integer = 27I
Dim intMonths As Integer
Dim decTotal As Decimal

'Move inputs from form into variables
intMonths = txtMonths.Text


'Processing

If Me.radSingle.Checked Then
decTotal = intSingle * intMonths
ElseIf Me.radFamily.Checked Then
decTotal = intFamily * intMonths
ElseIf Me.radAncient.Checked Then
decTotal = intAncient * intMonths
End If


'Move output to form objects
lblTotal.Text = decTotal.ToString("C")

No comments:

Post a Comment