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

Discussion in 'ASP General' started by Lakshmi Narayanan.R, Mar 2, 2005.

  1. Hi Experts,

    Using keyword "To" in select case giving error.The following code is got
    from www.microsrosoft.com itself. What is the wrong with this?.

    <%
    Dim Number1
    Number1 = 7 ' Initialize variable.
    Select Case Number1 ' Evaluate Number1.
    Case 1 To 5 ' Number1 between 1 and 5, inclusive.
    Response.Write( "Between 1 and 5" )
    ' The following is the only Case clause that evaluates to True.
    Case 6, 7, 8 ' Number1 between 6 and 8.
    Response.Write( "Between 6 and 8")
    Case 9 To 10 ' Number1 is 9 or 10.
    Response.Write( "Greater than 8")
    Case Else ' Other values.
    Response.Write( "Not between 1 and 10")
    End Select
    %>

    Thanx in advance
    Laks.R
     
    Lakshmi Narayanan.R, Mar 2, 2005
    #1
    1. Advertising

  2. Lakshmi Narayanan.R wrote:
    > Hi Experts,
    >
    > Using keyword "To" in select case giving error.The following code is
    > got from www.microsrosoft.com itself. What is the wrong with this?.


    The code you you got was written for VB/VBA. vbscript is not VB. The To
    keyword is not supported in vbscript.

    >
    > <%
    > Dim Number1
    > Number1 = 7 ' Initialize variable.
    > Select Case Number1 ' Evaluate Number1.
    > Case 1 To 5 ' Number1 between 1 and 5, inclusive.
    > Response.Write( "Between 1 and 5" )


    This should be:
    Response.Write "Between 1 and 5"

    Only use parentheses in VB/VBA/vbscript when calling a function whose return
    value you are consuming. If you were calling a method with more than one
    argument without consuming the return value, using parentheses would raise
    an error.

    By "consuming the return value" I mean:

    1. Setting the return value to a variable:
    Set a = createobject("some.class")
    Parentheses are required

    2. Evaluating the return value:
    Function test(x,y)
    if x>y then
    test=true
    else
    test=false
    end if
    end Function
    if test(10,5) then ...

    Again, parentheses are required.

    Calling test without consuming the return value requires that it be called
    like a Sub (with no parentheses):

    test 10, 5

    unless using the Call statement:
    Call test(10,5)

    More here:
    http://weblogs.asp.net/ericlippert/archive/2003/09/15/52996.aspx


    HTH,
    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], Mar 2, 2005
    #2
    1. Advertising

  3. Lakshmi Narayanan.R

    Evertjan. Guest

    Bob Barrows [MVP] wrote on 02 mrt 2005 in
    microsoft.public.inetserver.asp.general:
    > 2. Evaluating the return value:
    > Function test(x,y)
    > if x>y then
    > test=true
    > else
    > test=false
    > end if
    > end Function
    >


    Why not simply:

    Function test(x,y)
    test = x>y
    end Function


    --
    Evertjan.
    The Netherlands.
    (Replace all crosses with dots in my emailaddress)
     
    Evertjan., Mar 2, 2005
    #3
  4. Evertjan. wrote:
    > Bob Barrows [MVP] wrote on 02 mrt 2005 in
    > microsoft.public.inetserver.asp.general:
    >> 2. Evaluating the return value:
    >> Function test(x,y)
    >> if x>y then
    >> test=true
    >> else
    >> test=false
    >> end if
    >> end Function
    >>

    >
    > Why not simply:
    >
    > Function test(x,y)
    > test = x>y
    > end Function
    >
    >

    2 reasons:
    Clarity - While yours is more efficient, mine is clearer to the newbie. If I
    was writing it myself, I would use your version.

    The real reason: I originally wrote a different example, and when I changed
    it to this, I was too lazy to rewrite it using the more efficient version.
    :)

    Bob Barrows

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Mar 2, 2005
    #4
  5. Hi MVP's

    Did u run the code, i have pasted.

    What u said is correct for Functions other than comes in collections.
    So, writing Response.Write with paranthesis will work fine.
    My question is that the error comes in the line "case 1 to 5".

    So pls run the code run the code run the code and find the solution.

    Regards
    Laks.R

    "Bob Barrows [MVP]" wrote:

    > Lakshmi Narayanan.R wrote:
    > > Hi Experts,
    > >
    > > Using keyword "To" in select case giving error.The following code is
    > > got from www.microsrosoft.com itself. What is the wrong with this?.

    >
    > The code you you got was written for VB/VBA. vbscript is not VB. The To
    > keyword is not supported in vbscript.
    >
    > >
    > > <%
    > > Dim Number1
    > > Number1 = 7 ' Initialize variable.
    > > Select Case Number1 ' Evaluate Number1.
    > > Case 1 To 5 ' Number1 between 1 and 5, inclusive.
    > > Response.Write( "Between 1 and 5" )

    >
    > This should be:
    > Response.Write "Between 1 and 5"
    >
    > Only use parentheses in VB/VBA/vbscript when calling a function whose return
    > value you are consuming. If you were calling a method with more than one
    > argument without consuming the return value, using parentheses would raise
    > an error.
    >
    > By "consuming the return value" I mean:
    >
    > 1. Setting the return value to a variable:
    > Set a = createobject("some.class")
    > Parentheses are required
    >
    > 2. Evaluating the return value:
    > Function test(x,y)
    > if x>y then
    > test=true
    > else
    > test=false
    > end if
    > end Function
    > if test(10,5) then ...
    >
    > Again, parentheses are required.
    >
    > Calling test without consuming the return value requires that it be called
    > like a Sub (with no parentheses):
    >
    > test 10, 5
    >
    > unless using the Call statement:
    > Call test(10,5)
    >
    > More here:
    > http://weblogs.asp.net/ericlippert/archive/2003/09/15/52996.aspx
    >
    >
    > HTH,
    > 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"
    >
    >
    >
     
    Lakshmi Narayanan.R, Mar 3, 2005
    #5
  6. Lakshmi Narayanan.R wrote:
    > Hi MVP's
    >
    > Did u run the code, i have pasted.
    >
    > What u said is correct for Functions other than comes in collections.
    > So, writing Response.Write with paranthesis will work fine.


    Of course it works fine (sort of): there's only one argument. That does not
    mean it is correct. You are forcing the compiler to do a little extra work.
    Granted, you will not notice the extra work it's doing, but there is no
    reason to make it do it.

    > My question is that the error comes in the line "case 1 to 5".


    I answered that question. I understand there may be a language difference
    between us, but I did answer this.

    >
    > So pls run the code run the code run the code and find the solution.


    There is no need to run it.
    There is no solution for this in vbscript. It works in Visual Basic. It does
    NOT work in vbscript.
    There IS a workaround:

    Select Case true
    Case (Number1>=1 and Number1 <=5)
    ...
    End Select

    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], Mar 3, 2005
    #6
  7. Hi MVP's

    Thank u for ur reply.
    Removing the paranthesis also giving the same error for the word "TO" in the
    case 1 to 5

    The error is here

    Microsoft VBScript compilation error '800a0400'

    Expected statement

    /asp/casestat.asp, line 5

    Case 1 To 5 ' Number1 between 1 and 5, inclusive.
    -------^

    So pls take a little effort and reply me.
    Thanx for ur suggession

    Laks.R

    "Bob Barrows [MVP]" wrote:

    > Lakshmi Narayanan.R wrote:
    > > Hi MVP's
    > >
    > > Did u run the code, i have pasted.
    > >
    > > What u said is correct for Functions other than comes in collections.
    > > So, writing Response.Write with paranthesis will work fine.

    >
    > Of course it works fine (sort of): there's only one argument. That does not
    > mean it is correct. You are forcing the compiler to do a little extra work.
    > Granted, you will not notice the extra work it's doing, but there is no
    > reason to make it do it.
    >
    > > My question is that the error comes in the line "case 1 to 5".

    >
    > I answered that question. I understand there may be a language difference
    > between us, but I did answer this.
    >
    > >
    > > So pls run the code run the code run the code and find the solution.

    >
    > There is no need to run it.
    > There is no solution for this in vbscript. It works in Visual Basic. It does
    > NOT work in vbscript.
    > There IS a workaround:
    >
    > Select Case true
    > Case (Number1>=1 and Number1 <=5)
    > ...
    > End Select
    >
    > 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"
    >
    >
    >
     
    Lakshmi Narayanan.R, Mar 3, 2005
    #7
  8. Lakshmi Narayanan.R wrote:
    > Hi MVP's
    >
    > Thank u for ur reply.
    > Removing the paranthesis also giving the same error for the word "TO"


    The parentheses issue was not related to the "TO" issue. It was a side
    issue. I answered your question about "To" with my very first sentences:

    >>>

    The code you you got was written for VB/VBA. vbscript is not VB. The To
    keyword is not supported in vbscript.
    >>>


    Then in my second message:

    >>>

    There is no solution for this in vbscript. It works in Visual Basic. It does
    NOT work in vbscript.
    There IS a workaround:
    <snip - go back and read it yourself - it's time YOU made the effort to
    understand what I'm saying to you>
    >>>



    For the last time:
    The "TO" keyword is NOT LEGAL in the vbscript Case statement.
    You can download the vbscript documentation from here:
    http://tinyurl.com/7rk6

    <snip>
    >
    > So pls take a little effort and reply me.


    I provided a workaround for you in my previous reply. PLEASE READ THE ENTIRE
    MESSAGE! This is the second time you have accused me of not making any
    effort for you. It will be the last.

    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], Mar 3, 2005
    #8
  9. Lakshmi Narayanan.R

    Roland Hall Guest

    "Bob Barrows [MVP]" wrote in message
    news:OJWgVj%...
    : Lakshmi Narayanan.R wrote:
    : > Hi MVP's
    : >
    : > Thank u for ur reply.
    : > Removing the paranthesis also giving the same error for the word "TO"
    :
    : The parentheses issue was not related to the "TO" issue. It was a side
    : issue. I answered your question about "To" with my very first sentences:
    :
    : >>>
    : The code you you got was written for VB/VBA. vbscript is not VB. The To
    : keyword is not supported in vbscript.
    : >>>
    :
    : Then in my second message:
    :
    : >>>
    : There is no solution for this in vbscript. It works in Visual Basic. It
    does
    : NOT work in vbscript.
    : There IS a workaround:
    : <snip - go back and read it yourself - it's time YOU made the effort to
    : understand what I'm saying to you>
    : >>>
    :
    :
    : For the last time:
    : The "TO" keyword is NOT LEGAL in the vbscript Case statement.
    : You can download the vbscript documentation from here:
    : http://tinyurl.com/7rk6
    :
    : <snip>
    : >
    : > So pls take a little effort and reply me.
    :
    : I provided a workaround for you in my previous reply. PLEASE READ THE
    ENTIRE
    : MESSAGE! This is the second time you have accused me of not making any
    : effort for you. It will be the last.

    You know Bob, I'm so confused now. Could you go over it just one more time
    and what about that keyword IS, can I use that instead? (O:=

    --
    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, Mar 3, 2005
    #9
  10. I beg very very sorry Mr.Bob,

    As u said, i didnt read carefully after the first para.Seeing the replyies
    in small window, i did the mistake.

    Pls dont mistaken me.

    Thank u for ur solutions.

    Regards
    Laks.R

    "Bob Barrows [MVP]" wrote:

    > Lakshmi Narayanan.R wrote:
    > > Hi MVP's
    > >
    > > Thank u for ur reply.
    > > Removing the paranthesis also giving the same error for the word "TO"

    >
    > The parentheses issue was not related to the "TO" issue. It was a side
    > issue. I answered your question about "To" with my very first sentences:
    >
    > >>>

    > The code you you got was written for VB/VBA. vbscript is not VB. The To
    > keyword is not supported in vbscript.
    > >>>

    >
    > Then in my second message:
    >
    > >>>

    > There is no solution for this in vbscript. It works in Visual Basic. It does
    > NOT work in vbscript.
    > There IS a workaround:
    > <snip - go back and read it yourself - it's time YOU made the effort to
    > understand what I'm saying to you>
    > >>>

    >
    >
    > For the last time:
    > The "TO" keyword is NOT LEGAL in the vbscript Case statement.
    > You can download the vbscript documentation from here:
    > http://tinyurl.com/7rk6
    >
    > <snip>
    > >
    > > So pls take a little effort and reply me.

    >
    > I provided a workaround for you in my previous reply. PLEASE READ THE ENTIRE
    > MESSAGE! This is the second time you have accused me of not making any
    > effort for you. It will be the last.
    >
    > 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"
    >
    >
    >
     
    Lakshmi Narayanan.R, Mar 4, 2005
    #10
  11. Lakshmi Narayanan.R wrote:
    > I beg very very sorry Mr.Bob,
    >


    Apology accepted. Let's move on to the next problem. :)
    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], Mar 4, 2005
    #11
    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,913
    Herfried K. Wagner [MVP]
    Jun 23, 2004
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    991
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,258
    Smokey Grindel
    Dec 2, 2006
  4. sixteenmillion

    The giving that keeps on giving

    sixteenmillion, Nov 19, 2007, in forum: C Programming
    Replies:
    0
    Views:
    458
    sixteenmillion
    Nov 19, 2007
  5. aa
    Replies:
    14
    Views:
    341
Loading...

Share This Page