<< Prev        Next >>

ID : 3743

Select Case...End Select

Function

To execute one of statement blocks in accordance with the conditional expression value.

Syntax

Select Case formula
	Case condition 1
		'Statements
	Case condition n
		'Statements-n
	Case Else
		'ElseStatements
End Select

Guaranteed Entry

Formula
Designate a formula to compare with condition n. No array can be designated.
Condition n
Designate a condition for comparison with formula.

Description

Subject to a relationship where formula value and condition n designated after "Case" are met (True), the statement up to the next "Case" or "End Select" is executed. After the execution, the system navigates to the line after "End Select."

If "Else" is designated after "Case" and all designated condition ns are not applicable, ElseStatements is executed.

How to Designate Condition n

Condition n is compared with formula. Comparison designated by comparative operator is possible. Designation is made by attaching a comparative operator after Case Is.

In case of an equal sign (=), "Is =" can be omitted.

For the relation between a comparative operator and data type, refer to "Comparative Operator."

Select Case aaa
Case Is > bbb 'When aaa is larger than bbb
	'statements
Case Is < bbb 'When aaa is smaller than bbb
	'statements
Case bbb 'When aaa and bbb are the same values
	'statements
End Select
Special condition designation

A condition in which formula is higher than bbb and lower than ccc can be designated.

Select Case aaa
Case bbb To ccc
	'statements
End Select

If ccc is smaller than bbb, this condition is not True.

Designating multiple conditions

More than one condition can be designated with Or condition using "," between each condition.

Select Case aaa
Case Is <= 3 , 5 , 7 To 9 '3 or less, 5, 7 to 9
	'statements
Case Is > bbb , Is <= 0 'Larger than bbb, or lower than 0
	'statements
End Select

Attention

Other conditions cannot be stated after "Case Else."

Example

'!TITLE "Execution of Multiple Condition Judgement"
' Execute Case statement in which aaa is matched
Sub Sample_SelectCase

  Dim aaa As Integer
  aaa = 2

  ' When the aaa value is matched with Case statement value, execute the command
  Select Case aaa
  Case 0

    ' Output "0" to the message output window
    PrintDbg aaa

  Case 1

    ' Output "1" to the message output window
    PrintDbg aaa

  Case 2

    ' Output "2" to the message output window
    PrintDbg aaa

  Case 3

    ' Output "3" to the message output window
    PrintDbg aaa

  End Select

End Sub

ID : 3743

<< Prev        Next >>