Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

B. 4 Conditional Structures

Conditional Structures

The If statement uses the standard syntax of testing a condition and performing one action if the condition is true and another action if it’s false. The code in the Else block is executed if the test returns false. Basic syntax also supports the ElseIf statement. An If block must always be finished with and End If.

Basic syntax for a nested If statement:

If condition1 Then
…code…
ElseIf condition2 Then
…code…
Else
…code…
End If

In Basic syntax, the Select Case statement is built by first typing the keywords Select Case followed by the variable name you want to test. After that, list the test conditions and the related code blocks using Case statements. You can list multiple conditions for a single Case statement by separating the conditions with a comma. If none of the Case statements return true, then the code in the Case Else block is executed. Finish a Case block with End Select. The following code is a template for how to fill in a Case statement.

Select Case var
Case condition1
…code…
Case condition1, condition2
…code…
Case Else
…code…
End Select