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

M

Matt

<% 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!
 
G

Gervin

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.
 
B

Bob Barrows

Matt said:
<% 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
 
B

Brynn

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top