422,024 Members | 1,034 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,024 IT Pros & Developers. It's quick & easy.

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

P: n/a
<% 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!

Jul 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <ma*******@hotmail.com> wrote in message
news:uG**************@TK2MSFTNGP09.phx.gbl...
<% 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!

Jul 19 '05 #2

P: n/a
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"
Jul 19 '05 #3

P: n/a
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" <ma*******@hotmail.com>
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!


Jul 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.