IIS ASP - 'AS' keyword supported?

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > April 2006 > 'AS' keyword supported?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author 'AS' keyword supported?
Sean S - Perth, WA

2006-04-27, 7:52 am

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
---------^


--
Sean.
Mike Brind

2006-04-27, 7:52 am


Sean wrote:
> 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")

--
Mike Brind

Bob Barrows [MVP]

2006-04-27, 7:52 am

Sean S - Perth, WA wrote:
> 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

--
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"


Guffa

2006-04-27, 7:52 am

> VBscript is as follows:
>
> Dim conn
> SET conn = CreateObject("ADODB.Connection")


But in ASP use Server.CreateObject instead of CreateObject.
Bob Barrows [MVP]

2006-04-27, 7:52 am

Guffa wrote:
>
> But in ASP use Server.CreateObject instead of CreateObject.


That's debatable as well.
http://blogs.msdn.com/ericlippert/a.../01/145686.aspx

--
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"


Guffa

2006-04-27, 7:52 am

> That's debatable as well.
> http://blogs.msdn.com/ericlippert/a.../01/145686.aspx


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?
Bob Barrows [MVP]

2006-04-27, 7:52 am

Guffa wrote:
>
> 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.

--
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"


Guffa

2006-04-27, 7:52 am

> 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
Dave Anderson

2006-04-27, 7:52 am

Guffa wrote:
> 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.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms.


Guffa

2006-04-27, 7:52 am

"Dave Anderson" wrote:

> Guffa wrote:
>
> 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.
Sean S - Perth, WA

2006-04-27, 7:52 am

"Mike Brind" wrote:

> Nope. That's VB.


Ahhhhhhhhhh. <light bulb goes on>

Thanks to Bob B. too.

--
Sean.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com