'AS' keyword supported?

S

Sean S - Perth, WA

Hi all,

Is the keyword 'as' supported in ASP? I'm reasonably sure it's valid
VBScript (code examples I've downloaded use it) but when I try to use it in
ASP I get an error. Is it perhaps a version issue?


Expected end of statement

Dim conn As New ADODB.Connection
---------^
 
M

Mike Brind

Sean said:
Hi all,

Is the keyword 'as' supported in ASP? I'm reasonably sure it's valid
VBScript (code examples I've downloaded use it) but when I try to use it in
ASP I get an error. Is it perhaps a version issue?


Expected end of statement

Dim conn As New ADODB.Connection
---------^

Nope. That's VB.

VBscript is as follows:

Dim conn
SET conn = CreateObject("ADODB.Connection")
 
B

Bob Barrows [MVP]

Hi all,

Is the keyword 'as' supported in ASP? I'm reasonably sure it's valid
VBScript (code examples I've downloaded use it)

Those must be VB examples, not vbscript ...
but when I try to use
it in ASP I get an error. Is it perhaps a version issue?

ASP is not a language: it is a platform that supports the use of several
scripting languages, including vbscript, jscript and perlscript.
Expected end of statement

Dim conn As New ADODB.Connection
---------^

In vbscript, only variants are allowed, so no, the "AS [New] datatype" is
not allowed.

See the two topics about the differences between VB and VBScript in the
documentation you can download from: http://tinyurl.com/7rk6
 
B

Bob Barrows [MVP]

Guffa said:
Of course it is. Here's something for the debate:

Would you like to create a connection object in 0.4 ms or 0.15 ms?

The latter, of course. What are you saying? That you've got benchmark code
that proves CreateObject instantiates connection objects faster than
Server.CreateObject? If so, we'd all like to see it.
 
G

Guffa

The latter, of course. What are you saying? That you've got benchmark code
that proves CreateObject instantiates connection objects faster than
Server.CreateObject? If so, we'd all like to see it.

No, the opposite. Server.CreateObject is faster than CreateObject, as it
reuses the objects from the object pool.

The benchmark code is really simple:

<%

Dim a, t, obj

t = Timer
For a = 1 to 100000
Set obj = Server.CreateObject("ADODB.Connection")
Set obj = Nothing
Next
Response.Write Timer - t & "<br>"

t = Timer
For a = 1 to 100000
Set obj = CreateObject("ADODB.Connection")
Set obj = Nothing
Next
Response.Write Timer - t & "<br>"

%>

/Guffa
 
D

Dave Anderson

Guffa said:
Server.CreateObject is faster than CreateObject, as
it reuses the objects from the object pool.

Even if you can show that Server.CreateObject is faster, I'm not sure you
have the correct reason.

I use JScript on the Server, so CreateObject() alone is not an option (but
new ActiveXObject() is). I assume that's because JScript doesn't go looking
for the method in all of its available objects (Response, Server, Session,
etc.) if you don't specify one. VBScript *will* do this, so I further assume
it is using the CreateObject method of the Server Object anyway -- it just
has to find it each time it is called lazily.
 
G

Guffa

Dave Anderson said:
Even if you can show that Server.CreateObject is faster, I'm not sure you
have the correct reason.

I use JScript on the Server, so CreateObject() alone is not an option (but
new ActiveXObject() is). I assume that's because JScript doesn't go looking
for the method in all of its available objects (Response, Server, Session,
etc.) if you don't specify one. VBScript *will* do this, so I further assume
it is using the CreateObject method of the Server Object anyway -- it just
has to find it each time it is called lazily.

No, VBScript doesn't look for methods in the ASP objects. If you for an
example try to use just Write instead of Response.Write, it won't work.

Server.CreateObject is a method in the Server object, while CreateObject is
a command in VBScript.
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top