Syntax |
Select Case testexpression
[Case expressionlist
[statement_block]]
[Case expressionlist
[statement_block]]
.
.
[Case Else
[statement_block]]
End Select
|
Description |
Used to execute a block of the Basic Control Engine statements depending on the value of a given expression. |
Comments |
The
Select Case
statement has the following parts: |
|
Part |
Description |
|
testexpression |
Any numeric or string expression. |
|
statement_block |
Any group of the Basic Control Engine statements. If the testexpression matches any of the expressions contained in expressionlist, then this statement block will be executed. |
|
expressionlist |
A comma separated list of expressions to be compared against testexpression using any of the following syntaxes: expression
[,
expression
]...
expression
to
expression
is
relational_operator expression The resultant type of expression in expressionlist must be the same as that of testexpression. |
|
Multiple expression ranges can be used within a single
Case
clause. For example: Case 1 to 10,12,15 Is > 40 Only the statement_block associated with the first matching expression will be executed. If no matching statement_block is found, then the statements following the
Case Else
will be executed. A
Select...End Select
expression can also be represented with the
If...Then
expression. The use of the
Select
statement, however, may be more readable. |
Example |
This example uses the
Select...Case
statement to output the current operating system. Sub Main()
OpSystem% = Basic.OS
Select Case OpSystem%
Case 0,2
s = "Microsoft Windows"
Case 1
s = "DOS"
Case 3 to 8,12
s = "UNIX"
Case 10
s = "IBM OS/2"
Case Else
s = "Other"
End Select
MsgBox "This version of the Basic Control Engine is running on: " & s
End Sub
|
See Also |
Choose (function); Switch (function); IIf (function); If...Then...Else (statement) |