ASP Select Case Syntax Error (Case Condition)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • makinha
    New Member
    • Jul 2007
    • 3

    ASP Select Case Syntax Error (Case Condition)

    Hello, I am getting a syntax error
    Microsoft VBScript compilation error '800a0400'

    Expected statement
    line 49
    Case 164 To 269
    ---------------^
    (The error references to keyword "To")

    Is there anyone know if ASP support the keyword "To"? or it use another keyword to have the case condition in range? I know I can use a comma to form a multi condition, like "Case 164, 165, 166, 167", etc. However, I need a range from 164 to 269 which is alot. Any idea? Thanks.

    My code posted as below:
    =============== ========
    Select Case number
    Case 161
    result = "a"
    Case 162
    result = "b"
    Case 164 To 269
    result = "c"
    Case 276 To 314
    result = "d"
    Case Else
    result = "e"
    End Select
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    I would have thought VBScript used the exact same syntax for this type of thing as VB. I'll post in the VB forum to see if anyone there sees a problem I'm missing. If you only have 5 or six cases and you can't get the select to work, you might consider trying an unwieldy if...else statement. It will work even though it will be tiresome.

    Jared

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      I have recently been surprised to find that VB.Net doesn't seem to support the To keyword, so maybe ASP doesn't either. It certainly does look that way, to judge from your post. After all, how could you possibly have it wrong? Unless you've got some weird characters in there that we can't see, or some Unicode characters that just look like "To". But come on, how likely is that?

      One slightly ugly workaround might be to use this syntax (not tested)...

      Case Is >= 164 And <= 269

      I've probably got that wrong, but you get the idea - try manipulating the Is clause to get around the problem. If all else fails, does ASP support the ElseIf statement? It's very useful for making an extended IF structure that's almost as clean as Select Case, but has the advantage of allowing complex tests. For example, to rewrite your Select Case...

      [CODE=vb]If number = 161 Then
      result = "a"
      ElseIf number = 162 Then
      result = "b"
      ElseIf number >= 164 And number <= 269 Then
      result = "c"
      ElseIf number >= 276 And number <= 314 Then
      result = "d"
      Else
      result = "e"
      End If[/CODE]

      Comment

      • ilearneditonline
        Recognized Expert New Member
        • Jul 2007
        • 130

        #4
        Originally posted by Killer42
        One slightly ugly workaround might be to use this syntax (not tested)...

        Case Is >= 164 And <= 269
        Tested this and it doesn't work. The only why I know of is....
        [CODE=asp]
        Select Case number
        Case 161
        result = "a"
        Case 162
        result = "b"
        Case 164, 165, 166, ...
        result = "c"
        Case 276, 277, 278, ...
        result = "d"
        Case Else
        result = "e"
        End Select
        [/CODE]

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by ilearneditonlin e
          Tested this and it doesn't work. ...
          Bummer!

          Have you tried ElseIf? It's almost as compact and easy to read, and (if it is supported) wouldn't require huge lists of values.

          Comment

          Working...