In VB, the following form is preferred for implementing the If-Then-Else structure (this is the "block", or "multi-line" form of the If statement):
If
Else
End If
If the conditional expression is true, the statements between the keywords Then and Else will be executed (and the statements between the keywords Else and End If will be bypassed). If the conditional expression is false, the statements between the keywords Else and End If will be executed (and the statements between the keywords Then and Else will be bypassed). In any case, program control will resume with the statement following End If.
Example:
If sngNumberOfCredits <>
lblStatus = "PART-TIME STUDENT"
dblTuitionAmount = sngNumberOfCredits * 175
Else
lblStatus = "FULL-TIME STUDENT"
dblTuitionAmount = 2000
End If
STYLE TIPS FOR THE BLOCK IF STATEMENT:
(1) Indent the "true" actions 4 spaces from the keyword "If"
(2) Code the keyword "Else" on a separate line, aligned with the keyword "If"
(3) Code the "false" actions 4 spaces from the keyword "Else"
(4) Align the keywords "End If" with the keywords "If" and "Else"
No comments:
Post a Comment