tags:

views:

108

answers:

5

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?

+1  A: 

you do not need 'as'.

this should work.

<%
Dim myString
myString = "Hello There!"
%>
Omnipresent
Yes but I need to declare it specific as string.
You can't declare it as string. It has to be a variant
MarkJ
+1  A: 

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.

MarkJ
+3  A: 

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

dim i
i = "some string"
Austin Salonen
+3  A: 

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"
%>
Amadiere
Tnks its true, I cant use "as"
Just to clarify Classic ASP uses "a" script language which by and large is VBScript. However it may also be Javascript or any other script language designed to work with the windows script host.
AnthonyWJones
+1  A: 

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.

NobodyMan