InstallShield 2019 » InstallScript Language Reference
The switch statement is similar to the elseif Structure statement. Use the switch statement to execute one of several different sections of code, depending on the value of an expression. The switch statement evaluates the expression and then branches to the case statement whose constant value matches the result of the expression. If no match is found among the case statements, control passes to a default statement, if one has been specified.
Creating Switch Statements
To create a switch statement:
1. | Type the keyword switch, followed by the expression to be evaluated. The expression—which can be a constant, variable, arithmetic expression, logical expression, or function result—must be enclosed within parentheses. Do not punctuate this line. |
2. | For each option, type the keyword case and one or more constants followed by a colon. If more than one constant is specified, delimit them with commas. Note that only constants can be specified here. Specifying a variable name, string identifier, function result, or other type of expression after the keyword case results in an error. |
3. | For each case, follow the colon with the statement or statements to be executed for that option. Terminate each statement with a semicolon. |
4. | After all case statements have been specified, use the keyword default, followed by a colon (:), to control the program when the expression does not match any of the stated cases. |
5. | Close the block with the keyword endswitch, followed by a semicolon (;). |
Example Script
The following script segment displays the current video resolution of the computer on which it is executed:
STRING szMsg, svResult;
NUMBER nvResult;
GetSystemInfo (VIDEO, nvResult, svResult);
switch (nvResult)
case IS_UNKNOWN:
szMsg = "The user's video is unknown.";
case IS_EGA:
szMsg = "EGA resolution.";
case IS_VGA:
szMsg = "VGA resolution.";
case IS_SVGA:
szMsg = "Super VGA (800 x 600) resolution.";
case IS_XVGA:
szMsg = "XVGA (1024 x 768) resolution.";
case IS_UVGA:
szMsg = "Greater than 1024 x 768 resolution.";
default:
szMsg = "Error";
endswitch;
MessageBox (szMsg, INFORMATION);
Note • Only one case block is executed each time a switch statement is executed. After InstallShield executes a case block, it executes the next statement after the endswitch. A switch block can be quite useful inside of a while loop. By using the case statements as flags, you can create a loop with optional exit points.
InstallShield 2019 Help LibraryApril 2019 |
Copyright Information | Flexera |