Microsoft VBScript runtime (0x800A01F5): Illegal assignment: variable name

Discussion in 'ASP General' started by Matt, Jan 11, 2004.

  1. Matt

    Matt Guest

    <% hour = Request("controlname") %> will yield the following error:

    Microsoft VBScript runtime (0x800A01F5)
    Illegal assignment: 'hour'

    However, if I declare hour, then it is fine.
    <%
    Dim hour
    hour = Request("controlname")
    %>

    But I think in VBScript, declaration of a variable is optional? That means
    we can use the variable without writing "Dim hour" ??

    Please advise! thanks!
     
    Matt, Jan 11, 2004
    #1
    1. Advertising

  2. Matt

    Gervin Guest

    If u use a variable name that is NOT a function name as well, then u don't
    have to declare it.
    Hour( ) is a built-in function.

    "Matt" <> wrote in message
    news:...
    > <% hour = Request("controlname") %> will yield the following error:
    >
    > Microsoft VBScript runtime (0x800A01F5)
    > Illegal assignment: 'hour'
    >
    > However, if I declare hour, then it is fine.
    > <%
    > Dim hour
    > hour = Request("controlname")
    > %>
    >
    > But I think in VBScript, declaration of a variable is optional? That means
    > we can use the variable without writing "Dim hour" ??
    >
    > Please advise! thanks!
    >
    >
    >
     
    Gervin, Jan 11, 2004
    #2
    1. Advertising

  3. Matt

    Bob Barrows Guest

    Matt wrote:
    > <% hour = Request("controlname") %> will yield the following error:


    Hour() is a builtin vbscript function. Do NOT use ambiguous words for
    variable names.

    >
    > Microsoft VBScript runtime (0x800A01F5)
    > Illegal assignment: 'hour'
    >


    This is why "hour" should not be used for the variable name.

    > However, if I declare hour, then it is fine.


    No, it is not.

    > <%
    > Dim hour
    > hour = Request("controlname")
    > %>


    Try calling the Hour() function after declaring it as a variable.

    dim hour
    hour=3
    Response.Write(hour(#13:25:00#))

    You will quickly see why it is not fine. :)

    Now I realize that it can add much time to your coding if you have to look
    up all the variable names you wish to use in online documentation to make
    sure you aren't using a keyword. The solution is to use a naming convention
    that will guarantee that your variable names never conflict with builtin
    names. The convention can be as simple as always prefixing your variables
    with the letter "v", vHours instead of hours. Or it can be a little more
    informative (as well as making your code more self-documenting) by using
    "str" for string variables, "int" for integers, etc.

    >
    > But I think in VBScript, declaration of a variable is optional?


    That does not make it right to do so. Always use "Option Explicit" at the
    beginning of your code blocks. This will force you to declare your variables
    and prevent embarassing and time-consuming mistakes.

    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, Jan 11, 2004
    #3
  4. Matt

    Brynn Guest

    Yeah, just use theHour or somthing to that effect ... or when I am
    lazy, I will pout the letter z in front of everything .. LOL

    zHour


    On Sat, 10 Jan 2004 23:23:05 -0800, "Matt" <>
    wrote:

    ><% hour = Request("controlname") %> will yield the following error:
    >
    >Microsoft VBScript runtime (0x800A01F5)
    >Illegal assignment: 'hour'
    >
    >However, if I declare hour, then it is fine.
    ><%
    > Dim hour
    > hour = Request("controlname")
    >%>
    >
    >But I think in VBScript, declaration of a variable is optional? That means
    >we can use the variable without writing "Dim hour" ??
    >
    >Please advise! thanks!
    >
    >
    >
     
    Brynn, Jan 11, 2004
    #4
    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. PaulieS
    Replies:
    1
    Views:
    3,272
    Kevin Spencer
    Nov 28, 2005
  2. Replies:
    0
    Views:
    932
  3. Rahul Bakshi

    Microsoft VBScript runtime error '800a01c9'

    Rahul Bakshi, Sep 28, 2003, in forum: ASP General
    Replies:
    3
    Views:
    167
    Ray at
    Sep 28, 2003
  4. nicholas.gadacz

    Microsoft VBScript runtime error '800a0046'

    nicholas.gadacz, Oct 21, 2003, in forum: ASP General
    Replies:
    3
    Views:
    446
    Bob Barrows
    Oct 22, 2003
  5. Matt
    Replies:
    3
    Views:
    231
    Matthew Louden
    Jan 9, 2004
Loading...

Share This Page