Case and Switch

 

The Switch/Case group of commands allows for the writing of complicated conditional statements that are simpler and more readable than those using a number of nested If Variable statements. Pascal or C programmers will recognize that these commands are similar to the Switch/Case statements in C and the Case statement in Pascal.

 

The Switch/Case commands test the content of a single variable against a series of values and execute specific macro commands based on the value in the variable.

 

A Switch/Case block of macro commands always begins with the Switch command and ends with the End Switch command. Place one or more Case/End Case blocks inside the Switch/Case block. The Case/End blocks begin with a Case command and end with an End Case command. Optionally include one Default Case/End Case block.

 

 


 

 

Switch

The Switch command requires a variable. This may include any type of variable, such as Integer, Text or Decimal. But all values in the Case statements that follow must be consistent with the type of variable chosen for the Switch statement. If the values are not consistent, the results may be unpredictable.

 

 

Script Editor > Expand Logic Category > Switch

 

 

End Switch

The End Switch command is required to end a Switch Block and is similar to the "End If" command. No edit window is available. The command is inserted directly into the script.

 

 


 

 

Case

The Case command starts a Case/End Case block of macro commands.

 

 

Script Editor > Expand Logic Category > Case

 

The Case command may contain a variable or it may contain a value that is entered directly in the Case command. For example, use a value of %T[2]% or enter a text string such as "Done".

 

A Case/End Case block may contain more than one Case command with a single End Case command at the end of the block.

 

 

Sample Macro

 

This example tests the value in the T[1] variable for the word Found or any of the words Done, Finished or Completed.

 

Switch (%T[1]%)

  Case: Found

    Text Box Display: T[1] equals Found

  End Case

  Case: Done

  Case: Finished

  Case: Completed

    Text Box Display: The comparison is done

  End Case

End Switch

 

 

Default Case

The Default Case/End Case block is optional. This command is similar to the standard case, but acts like an "Else" command. Basically, if none of the conditions are met in the previous case statements, then the default case is executed. No edit window is available. The command is inserted directly into the script.

 

If used, the Default Case/End Case block must be placed after all other Case/End Case blocks. Any Case commands that follow the Default Case command will not run.

 

 

Sample Macro

 

This example tests the variable T[1] for the word Found.

 

Switch (%T[1]%)

  Case: Found

    Text Box Display: T[1] equals Found

  End Case

  Default Case

    Text Box Display: T[1] does not equal Found

  End Case

End Switch

 

 

A Case command and a Default Case command may be combined in a single block.

 

 

Sample Macro

 

In this example, if the variable T[1] either contains the word Searching or if it does not contain the word Found, then the commands in the Default Case block will run.

 

Switch (%T[1]%)

  Case: Found

    Text Box Display: T[1] equals Found

  End Case

  Case: Searching

  Default Case

    Text Box Display: T[1] does not equal Found

  End Case

End Switch

 

 

End Case

The End Case command defines the end of a Case/End Case or Default Case/End Case block of macro commands. No edit window is available. The command is inserted directly into the script.