What's wrong with this Select Case Syntax?

Discussion in 'ASP General' started by Penny, May 13, 2005.

  1. Penny

    Penny Guest

    Hi all,

    My browser throws this Select Case block back at me pointing out a syntax
    error on the line: 'Case < 251', between the word 'Case' and the '<' symbol.

    ***************************

    intWeightTotal = 550

    Select Case intWeightTotal
    Case < 251
    ' Do something
    Case < 501
    ' Do something
    Case < 1001
    ' Do something
    Case < 2001
    ' Do something
    Case Else
    ' Do something else
    End Select

    **************************

    All my other Select Case blocks work fine without the '<' symbol.

    I've also tried the line 'Case Is < 251' but same error.

    Any ideas?

    Regards

    Penny.
     
    Penny, May 13, 2005
    #1
    1. Advertising

  2. Penny

    Roland Hall Guest

    "Penny" <> wrote in message
    news:...
    : Hi all,
    :
    : My browser throws this Select Case block back at me pointing out a syntax
    : error on the line: 'Case < 251', between the word 'Case' and the '<'
    symbol.
    :
    : ***************************
    :
    : intWeightTotal = 550
    :
    : Select Case intWeightTotal
    : Case < 251
    : ' Do something
    : Case < 501
    : ' Do something
    : Case < 1001
    : ' Do something
    : Case < 2001
    : ' Do something
    : Case Else
    : ' Do something else
    : End Select
    :
    : **************************
    :
    : All my other Select Case blocks work fine without the '<' symbol.
    :
    : I've also tried the line 'Case Is < 251' but same error.
    :
    : Any ideas?

    Try this:

    Select Case True
    Case intWeightTotal < 251
    ' Do something
    Case intWeightTotal < 501
    ' Do something
    Case intWeightTotal < 1001
    ' Do something
    Case intWeightTotal < 2001
    ' Do something
    Case Else
    ' Do something else
    End Select

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 13, 2005
    #2
    1. Advertising

  3. Penny

    Penny Guest

    Thanks Roland,

    It now works with your code tip.

    All the documentation I could find told me to do it the original way I tried
    which is a bit frustrating.

    Thanks again!

    Regards

    Penny.

    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    > "Penny" <> wrote in message
    > news:...
    > : Hi all,
    > :
    > : My browser throws this Select Case block back at me pointing out a

    syntax
    > : error on the line: 'Case < 251', between the word 'Case' and the '<'
    > symbol.
    > :
    > : ***************************
    > :
    > : intWeightTotal = 550
    > :
    > : Select Case intWeightTotal
    > : Case < 251
    > : ' Do something
    > : Case < 501
    > : ' Do something
    > : Case < 1001
    > : ' Do something
    > : Case < 2001
    > : ' Do something
    > : Case Else
    > : ' Do something else
    > : End Select
    > :
    > : **************************
    > :
    > : All my other Select Case blocks work fine without the '<' symbol.
    > :
    > : I've also tried the line 'Case Is < 251' but same error.
    > :
    > : Any ideas?
    >
    > Try this:
    >
    > Select Case True
    > Case intWeightTotal < 251
    > ' Do something
    > Case intWeightTotal < 501
    > ' Do something
    > Case intWeightTotal < 1001
    > ' Do something
    > Case intWeightTotal < 2001
    > ' Do something
    > Case Else
    > ' Do something else
    > End Select
    >
    > --
    > Roland Hall
    > /* This information is distributed in the hope that it will be useful, but
    > without any warranty; without even the implied warranty of merchantability
    > or fitness for a particular purpose. */
    > Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    > WSH 5.6 Documentation -

    http://msdn.microsoft.com/downloads/list/webdev.asp
    > MSDN Library - http://msdn.microsoft.com/library/default.asp
    >
    >
     
    Penny, May 13, 2005
    #3
  4. Penny

    Roland Hall Guest

    "Penny" wrote in message news:42846286$...
    : Thanks Roland,
    :
    : It now works with your code tip.
    :
    : All the documentation I could find told me to do it the original way I
    tried
    : which is a bit frustrating.
    :
    : Thanks again!

    You're welcome. I hear ya'. I remember searching quite awhile for this
    once myself.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 13, 2005
    #4
  5. Penny wrote:
    > Hi all,
    >
    > My browser throws this Select Case block back at me pointing out a
    > syntax error on the line: 'Case < 251', between the word 'Case' and
    > the '<' symbol.


    That's VB/VBA syntax that does not work in vbscript. It's just one of the
    many differences that can be found between the two languages. Unfortunately,
    not all these differences are well-documented; however, this one is ...
    somewhat. You have to read this article:

    Visual Basic for Applications Features Not In VBScript
    http://msdn.microsoft.com/library/en-us/script56/html/vsgrpNonFeatures.asp


    Where you'll find this text in the "Select Case" row:
    Expressions containing _Is_ keyword or any comparison operators
    Expressions containing a range of values using the To keyword.

    Roland already showed you the usual workaround so I won't repeat it here.

    You can download an installable version of te WSH documentaion here:
    http://tinyurl.com/7rk6

    Bob Barrows

    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows [MVP], May 13, 2005
    #5
  6. It's really weird too because this code definetly works and it does not
    mention the variable in each case
    I have used case statements like in this example for many years now

    http://www.powerasp.com/content/code-snippets/asp-randomizer.asp



    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    > "Penny" wrote in message news:42846286$...
    > : Thanks Roland,
    > :
    > : It now works with your code tip.
    > :
    > : All the documentation I could find told me to do it the original way I
    > tried
    > : which is a bit frustrating.
    > :
    > : Thanks again!
    >
    > You're welcome. I hear ya'. I remember searching quite awhile for this
    > once myself.
    >
    > --
    > Roland Hall
    > /* This information is distributed in the hope that it will be useful, but
    > without any warranty; without even the implied warranty of merchantability
    > or fitness for a particular purpose. */
    > Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    > WSH 5.6 Documentation -
    > http://msdn.microsoft.com/downloads/list/webdev.asp
    > MSDN Library - http://msdn.microsoft.com/library/default.asp
    >
    >
     
    Kyle Peterson, May 13, 2005
    #6
  7. Penny

    Roland Hall Guest

    "Kyle Peterson" wrote in message
    news:%...
    : It's really weird too because this code definetly works and it does not
    : mention the variable in each case
    : I have used case statements like in this example for many years now
    :
    : http://www.powerasp.com/content/code-snippets/asp-randomizer.asp

    Kyle...

    I don't think that's a true comparison to her issue. She's working with
    ranges.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 13, 2005
    #7
  8. you sir are correct
    it is different

    seems the the variable is needed when using "<" and what not


    "Roland Hall" <nobody@nowhere> wrote in message
    news:eFOZ8K$...
    > "Kyle Peterson" wrote in message
    > news:%...
    > : It's really weird too because this code definetly works and it does not
    > : mention the variable in each case
    > : I have used case statements like in this example for many years now
    > :
    > : http://www.powerasp.com/content/code-snippets/asp-randomizer.asp
    >
    > Kyle...
    >
    > I don't think that's a true comparison to her issue. She's working with
    > ranges.
    >
    > --
    > Roland Hall
    > /* This information is distributed in the hope that it will be useful, but
    > without any warranty; without even the implied warranty of merchantability
    > or fitness for a particular purpose. */
    > Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    > WSH 5.6 Documentation -
    > http://msdn.microsoft.com/downloads/list/webdev.asp
    > MSDN Library - http://msdn.microsoft.com/library/default.asp
    >
    >
     
    Kyle Peterson, May 13, 2005
    #8
  9. Penny

    Roland Hall Guest

    "Kyle Peterson" <> wrote in message
    news:eOAuuR$...
    : you sir are correct
    : it is different
    :
    : seems the the variable is needed when using "<" and what not

    I guess we'll never know why MSFT made it different. It sure adds to the
    confusion.

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, May 13, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tee
    Replies:
    3
    Views:
    7,904
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  2. Kevin

    Select Case Syntax Error

    Kevin, Aug 27, 2004, in forum: ASP General
    Replies:
    8
    Views:
    207
    Harag
    Aug 28, 2004
  3. Lakshmi Narayanan.R

    "Case 1 To 5" in Select case, giving Error!!. Why?

    Lakshmi Narayanan.R, Mar 2, 2005, in forum: ASP General
    Replies:
    10
    Views:
    366
    Bob Barrows [MVP]
    Mar 4, 2005
  4. aa
    Replies:
    14
    Views:
    340
  5. Jed Kowalski

    something wrong with case/when syntax

    Jed Kowalski, Jun 10, 2008, in forum: Ruby
    Replies:
    6
    Views:
    146
    Jed Kowalski
    Jun 10, 2008
Loading...

Share This Page