MicroStation CONNECT Edition Help

Switch Statements

The switch statement is similar to the if-then-else-endif statement in that it enables you to control the flow of the design script program based on an element's attributes. The syntax for the switch statement is as follows:

switch (expression)
 case value1 ?
		1 or more statements 
	case value2 ?
		1 or more statements
...
 default ?
	 1 or more statements
endswitch

The switch expression is evaluated and successively compared against the values associated with the case keyword. The values (for example, value1, value2, and so forth) must be constants, constant expressions, or a numeric range. If the expression and a value are equivalent or if the expression is in the range of the value, the statements following the case statement up to the next case are executed. The optional default case is executed if the expression does not match any of the case values. The following are two examples of the switch statement:

Example 1:

switch (level)
	case 20 ?
		color = "blue"
 	thickness = 0.25
	case 30-40 ?
 	color = "red"
		thickness = 0.3
endswitch

Example 2:

 switch (weight)
case 0-5 ?
	thickness = 0.25
case 6-10 ?
	thickness = 0.5
default ?
	thickness = 0.75
endswitch