user136224
user136224

Reputation: 153

Error declaring a variable in ASP

I'm declaring a string variable this way in classic ASP:

Dim i As String

And getting this error:

Microsoft VBScript compilation error '800a0401' 

Expected end of statement
/retencion/Estadisticas/Detail.asp, line 10, column 6

Dim i As String
-----^

Why is that?

Upvotes: 2

Views: 8971

Answers (5)

NobodyMan
NobodyMan

Reputation: 2451

This has been sufficiently answered I think, but I'll only chime in a bit to say that technically you may not need to explicitly declare the variable at all. If you're using the option explicit, yes you do need to declare it, a la

<%
option explicit

dim str:  str = "Hello World"
%>

Otherwise, you can implicitly declare it on first use, php-style.

<%
 str = "I don't need no stinkin dim statements!"
%>

I should add that using option explicit is a safer way to go, even if it does require more typing.

Upvotes: 2

Amadiere
Amadiere

Reputation: 11426

Classic ASP is written in VBScript and isn't Visual Basic itself, so you can't declare things as strings. Loosely typed I think is the phrase to describe it. Basically, you have to leave out the "as" and anything after it.

Try:

<%
Dim i

'you can now use the variable as you want.
i = "whatever"
%>

Upvotes: 7

Austin Salonen
Austin Salonen

Reputation: 50245

It's actually VBScript. You have to do this:

dim i
i = "some string"

Upvotes: 4

MarkJ
MarkJ

Reputation: 30408

I believe in classic ASP you can't give an explicit type to your variables. They all have to be variants and they have to be declared with no As clause, e.g. "dim i". Here's the MSDN help on variants in VBScript.

Upvotes: 3

Omnipresent
Omnipresent

Reputation: 30424

you do not need 'as'.

this should work.

<%
Dim myString
myString = "Hello There!"
%>

Upvotes: 1

Related Questions