How to add your knowledge

Select...Case Statement

    Table of contents
    No headers

    The Select...Case statement compares the value of one or more separate case statements to a select expression. The case statements are evaluated in the order in which they are declared until one of them matches the select expression. When a case statement matches the select expression, then the statement block associated with the case statement is executed. If no case statement matches the select expression, and an optional Case Else statement is present, then its statement block is executed, otherwise control passes to the end of the Select statement.

    The following example shows a simple Select...Case statement. In the example, the value of nTeeth (the number of teeth in a sprocket) is compared to a series of case clauses. When a match is found, the statement in the matching case clause sets the value of description. If none of the cases match, then the statement inside the optional Case Else clause is executed.

    Select nTeeth
       Case 18
          description = "18 Tooth Sprocket"
       Case 21
          description = "21 Tooth Sprocket"
       Case 25
          description = "25 Tooth Sprocket"
       Case Else
          description = "Default"
    End Select

    A case clause can consist of a simple expression, as in the previous example, or a list of expressions (comma-separated), as in the example below.

    Select LinkArmAssy.length
       Case 150, 175, 200
          boltDia = 12.0
       Case 225
          boltDia = 16.0
       Case 250, 275
          boltDia = 20.0
       Case Else
          boltDia = 24.0
    End Select

    In the preceding example, the select statement is the length rule of the LinkArmAssy part. The first case consists of three expressions, separated by commas. If the value of the length rule matches any one of the three expressions, then the statement block that is associated with the case is executed.