beautypg.com

Campbell Scientific CR5000 Measurement and Control Module User Manual

Page 222

background image

Section 9. Program Control Instructions

9-16

The argument expressionlist has these parts:

Part

Description

expression

Any numeric expression.

To

Keyword used to specify a range of values. If you use the To
keyword to indicate a range of values, the smaller value
must precede To.

Although not required, it is a good idea to have a Case Else statement in your
Select Case block to handle unforeseen testexpression values.

You can use multiple expressions or ranges in each Case clause. For example,
the following line is valid:

Case 1 To 4, 7 To 9, 11, 13

Select Case statements can be nested. Each Select Case statement must have a
matching End Select statement.

Select Case Statement Example

The example uses Select Case to decide what action to take based on user
input.

Dim X, Y

'Declare variables.

If Not X = Y Then

'Are they equal

If X > Y Then

Select Case X

'What is X.

Case 0 To 9

'Must be less than 10.

. . . .

'Run some code.

. . . .

'Run some code.

Case 10 To 99

'Must be less than 100.

. . . .

'Run some code.

. . . .

'Run some code.

Case Else

'Must be something else.

. . . .

'Run some code.

End Select

End If

Else

Select Case Y

'What is Y.

Case 1, 3, 5, 7, 9

'It's odd.

. . . .

'Run some code.

Case 0, 2, 4, 6, 8

'It's even.

. . . .

'Run some code.

Case Else

'Out of range.

. . . .

'Run some code.

. . . .

'Run some code.

End Select

End If
. . . .

'Run some code.

. . . .

'Run some code.