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:
    Case value2:
    Case value3:
    Case value4:
    Case Else:
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:

  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

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