Results 1 to 8 of 8

Thread: Select Case

  1. #1
    chenko
    Guest

    Unhappy Select Case

    Is there an Easy way to do this in ASP? Ive tried but I get a "Expected statement " error

    Code:
    Select Case iNumber
       Case 0 to 5
       Case 6 to 10
       Case 11 to 20
       Case 21 to 40
       Case 41 to 70
       Case 71 to 99
       Case > 99
       Case Else
    End Select

    Cheers!

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Well, you could do this with a series of if/elsif, but to do it with a select switch...

    First off, I assume you are using VBScript. Mind you ASP is not a language, it is a server-side technology. You could use JScript (among many others). I would suggest looking into JScript to see if the switch structure is more flexible.

    In VBScript, I would suggest trying Case (> x and < y). It may not work, but I'm sure to won't. To implies that it is going to step through a series, as in a for loop.

    Anyway, these aren't the answers, just a step toward finding them.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3
    Addicted Member csammis's Avatar
    Join Date
    Mar 2001
    Location
    /dev/null
    Posts
    226
    CiberTHuG, are you sure about "X To Y" not working? It works in regular VB, and if it's VBScript in question, the syntax is pretty much the same for logic structures
    Things I've Said:
    "Life's funny like that...elephants can wear frilly lace panties, and Dubya still looks like a monkey in a big chair"
    "Take four goats and strap one to each foot of a llama. Presto, goat-powered llama!"
    "You want to get me to work more, get me a Coke. No? Then deal with inferior garbage, I'm not coding another line and your clients can go to......thanks, I'd love a Coke right about now!"

  4. #4
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    This this code...

    Code:
    <%
      x = 20
      Select Case x
        Case 0 to 5
          Response.Write("0 to 5")
        Case 6 to 10
          Response.Write("6 to 10")
        Case 11 to 20
          Response.Write("11 to 20")
        Case 21 to 40
          Response.Write("21 to 40")
        Case 41 to 70
          Response.Write("41 to 70")
        Case > 71
          Response.Write("> 71")
        Case Else
          Response.Write("0 to 5")
      End Select
    %>
    I get this error

    Code:
    Microsoft VBScript compilation (0x800A0400)
    Expected statement
    /test/case.asp, line 4, column 7
    Case 0 to 5
    ------^
    I'll look into it some more.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  5. #5
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    In the meantime...

    Code:
    if (x > 0 and x < 6) then
      'do something
    elseif(x > 5 and x < 11) then
      'do something
    else
      'do something
    end if
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  6. #6
    Lively Member harsoni's Avatar
    Join Date
    Oct 2000
    Posts
    118

    Unhappy

    even i had the same problem then finally we used IF statements..

    Sonia:

  7. #7
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330
    Hi,
    It's the to statement that ASP doesn't like.
    The following does work but it might be rather cumbersome if your case statements have a large range.
    Code:
    <%
      x = 20
      Select Case x
        Case 0,1,2,3,4,5
          Response.Write("0 to 5")
        Case 6,7,8,9,10
          Response.Write("6 to 10")
        Case 11,12,13,14,15,16,17,18,19,20
          Response.Write("11 to 20")
        Case 21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40
          Response.Write("21 to 40")
        'Case 41 to 70
        '  Response.Write("41 to 70")
        'Case > 71
        '  Response.Write("> 71")
        'Case Else
        '  Response.Write("0 to 5")
      End Select
    %>
    Al.
    A computer is a tool, not a toy.

  8. #8
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Yeah, Chenko, its messy. The if/elseif will work better. You could always move on to a better language: JScript, Perl....
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width