ASP   «Prev 

ASP Select - Case Structure

Select and Case Structure in ASP

As mentioned in the lesson text, the Select/Case structure can contain as many Case tests as needed. All comparison operators can be used. The colon at the end of each Case statement is optional.
Here is the syntax:

Select Case variable
    Case value1:
        <statement>
    Case value2:
        <statement2>
    Case value3:
        <statement3>
    Case value4:
        <statement4>
    Case Else:
        <statement>
End Select

One use of this structure in our T-shirt store might be to set the value of a character variable to the spelled-out shirt size based upon a one-letter code input by the user. Here is a code segment that accomplishes this:

<HTML>
          .
          .
  <%	'BEGIN ASP SCRIPT
  Select Case cSizeAbbrev 
    Case "S"
      cSizeFull = "Small"
    Case "M"
      cSizeFull = "Medium"
    Case "L"
      cSizeFull = "Large"
    Case "XL"
      cSizeFull = "Extra-Large"
    Case Else
      cSizeFull = "Unknown"
  End Select
  %>
<!–END ASP SCRIPT ––>
            .
            .
</HTML>

This spelled-out text in the variable can be used later to print a receipt or display a message to the user.