Download Total Visual CodeTools Manual

Transcript
The SELECCT..CASE statement makes it clear that only one variable or
expression is being evaluated:
Select Case strValue
Case "Table": intResult = 1
Case "Query": intResult = 2
Case "Form": intResult = 3
End Select
Example of a SELECT..CASE Statement
In the example above, the resulting variable assignment is put on the same
line followed by a colon. Some people prefer that compact layout to make
it easier to see the assignment, but this is a more standard result:
Select Case strValue
Case "Table":
intResult = 1
Case "Query":
intResult = 2
Case "Form":
intResult = 3
End Select
Example of a SELECT..CASE Statement with Results on a Separate Line
Of course there could be more lines after each Case line. Another benefit of
a Case statement is that it can have multiple values or a range of values
which eliminates the use of many OR statements. For instance, this would
assign intResult to 1 if the value was either “Table” or “Query”:
Case "Table", "Query":
intResult = 1
Look in your VB/VBA help file for complete SELECT CASE syntax options.
Invoking the Select Case Builder
The Select Case Builder simplifies the creation of a Select Case statement by
letting you easily list the items you want to evaluate and assign a variable
based on the value. Choose the “Select Case Builder” from the Total Visual
CodeTools menu or toolbar:
96  Chapter 4: Code Builders
Total Visual CodeTools