Ability to Control Flow |
Flow Control is the ability to evaluate a "conditional expression". If a condition is satisfied, the program will perform a particular action. Multiple actions may be defined, with the execution of each action dependent on a particular outcome of the "condition" test.
The simplest flow control in Visual Basic is done with If and Else statements. If and Else statements can be used to program statements such as:
If the price is greater than $100, then perform a function, computation or other task. Otherwise, perform a different function, computation, or task.
Using If and Else statements, we can program this in Visual Basic:
If Field("price") > $100 Then
message = "Please call manager to double-check payment."
Else
message = "Process order normally."
End If
The above example sets the variable "message" differently depending on whether or not the price field in the current database is greater than $100.
For an alternative to using If
and Else
statements, refer to Using the In-line If (IIF) Function.
Other types of Flow Control statements are available in VB. Some "branch," like the If-Else statements discussed above, while others "loop."
To view more details on control flow statements
Related Topics