Name:
case
Syntax:

SELECT CASE variable
  CASE value
     {code}
  CASE value, value...
     {code}
  CASE value TO value
     {code}
  CASE comparison value
     {code}
  ELSE

     {code}
ENDSELECT

Variable - is the value to test.

Value - is a variable or constant to test againt

Comparison - can be any of the following conditions

= equal to
is equal to
<> not equal to
!= not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
Description:

The select case command conditionally executes sections of code depending on a variable's value; the 'case' commands specify what those conditions are.

Multiple 'case' tests can check for various conditions and if those conditions are met then the associated code is executed and then execution continues after the endselect command. Only one condition will ever be met within and 'select case' command and only one section of associated code will be executed.

If a condition test is not met then program execution continues with the next case command. If that condition is met then the associated code is executed and then execution continues after the endselect command.

If no conditions have been met and an 'else' command is encountered then its associated code will be executed. The code associated with the 'else' condition is only executed when no other condition has been met.

 

CASE value

If the 'select case' variable matches the value then the associated code will be executed. Then code execution continues after the endselect command.


CASE value, value...

Additional values to be checked for by adding them as a comma seperated list after the 'case' command. If the 'select case' variable matches any of the values then the associated code will be executed. Then code execution continues after the endselect command.

 

CASE value TO value

If the 'select case' variable has a value of or between the two values specified then the associated code will be executed. Then code execution continues after the 'endselect' command. Note that the left-most value must be less than or equal to the right-most value.

 

CASE comparison value 

The 'select case' variable is compared to the value specified using the comparison operator specified and if the comparison evaluates as true the associated code will be executed. Then code execution continues after the endselect command. The comparison operator can be any of the following conditions -

= equal to
is equal to
<> not equal to
!= not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
Applies To:
All
See Also:
Related Create:
    Share:
    Print:

    Switch outputs depending on the value of a variable

    Switch outputs 1 and 2 on or off depending on the value of variable b1

    Code Example:
    	select case b1
    	  case 1		'if b1 is 1, turn output 1 on
    	    high 1
    	  case 2,3		'if b1 is 2 or 3, turn output 1 off
    	    low 1
    	  case 4 to 6		'if b1 is between 4 and 6 (inclusive), turn output 2 on
    	    high 2
    	  else			'if none of these are true, turn output 2 off
    	    low 2
    	endselect
    Copy Code Submit an Example

    Submit Your Own Code!

    You must be logged in to submit code examples. Login now.