Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBScript Class scope in ASP pages?

90 views
Skip to first unread message

Mikkel Lauritsen

unread,
Oct 22, 1999, 3:00:00 AM10/22/99
to
Hi all,

I have been trying to pass VBScript classes between ASP pages by set-
ting references to them in the Session object, but it doesn't really
work.

An example:


Page1.asp:

<%@ LANGUAGE = VBScript %>
<%
Class MyClass
Public x
End Class

Dim c
Set c = New MyClass
c.x = 123

Set Session("MyC") = c

Response.Write("c is a " & TypeName(c) & "<br>")
Response.Write("c.x is " & c.x & "<br>")
%>


Page2.asp:

<%@ LANGUAGE = VBScript %>
<%
Dim c
Set c = Session("MyC")

Response.Write("c is a " & TypeName(c) & "<br>")
Response.Write("c.x is " & c.x & "<br>")
%>

As expected, requesting page1.asp gives

c is a MyClass
c.x is 123

as result, but requesting page2.asp gives

c is a MyClass

Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'x'
/page2.asp, line 7


- so enough of the class definition has survived to enable the TypeName
function to give the correct result, but the properties and methods are
not available. I have tried including the class definition on page2.asp
and adding a method to get the value of the property, but to no avail.

Am I trying to do something impossible or is there a solution that I
have overlooked?

TIA,
Mikkel Lauritsen

Ben Carter

unread,
Oct 22, 1999, 3:00:00 AM10/22/99
to
Session variables really don't like objects or collections, though the
lines on what a session variable can/can't handle are a little fuzzy.

For example, you can pass an array successfully in the same way as you
have tried, but the dictionary object will have similar results to what
you found.

Feel free to correct me if I'm wrong or if you can solidify what I have
said.
Tx.

--
//////////////////O\\\\\\\\\\\\\\\\\\
//// \\\\
/// Ben S. Carter, \\\
// Web Application Developer, \\
/ Bluewater Parklands Mgmt. Inc. \
> Guelph, ON, N1H 3G3 <
\ 519-766-0901 Ext. 226 /
\\ b...@camis.com //
\\\ webm...@camis.com ///
\\\\ ////
\\\\\\\\\\\\\\\\\\O//////////////////

Mikkel Lauritsen

unread,
Oct 22, 1999, 3:00:00 AM10/22/99
to
Ben Carter wrote:

> Session variables really don't like objects or collections, though the
> lines on what a session variable can/can't handle are a little fuzzy.

Tell me about it. The documentation that I have been able to obtain
sucks badly - for some reason MS are always extremely vague about things
that are just a bit more advanced than Hello World and friends.



> For example, you can pass an array successfully in the same way as you
> have tried, but the dictionary object will have similar results to what
> you found.

Well, in my experience putting objects like dictionaries in the Session
works without problems at all. [Just hacking up a small test script...]
Yup, no problems having a Dictionary survive between pages.

I have really been looking forward to having objects in VBScript in ASP
pages, but the current implementation is just... well, lousy IMHO.

Thanks for your help, anyway.

Mikkel Lauritsen

Jody Ansley

unread,
Oct 22, 1999, 3:00:00 AM10/22/99
to

------------------------------------------------------------

Hi there...

I've been in your shoes and I had a frustrating time
before I learned that one simply cannot put objects
instantiated from VBScript Classes in Session scope.

To my understanding, the built-in ASP Session object
will only store objects if they are apartment-threaded
or both-threaded (although storing anything in Session
scope is a scalability no-no).

Objects created from VBScript Classes are not actually
instances of compiled code. Instead, they are instances
of a Class. So I don't think they are threaded at all.
(...Or if they are threaded, I don't know what threading
model they use.)

If you're trying to persist the data in your classes
from one ASP page to the next, try some of the methods
in this article:

http://www.aspzone.com/articles/jody/PseudoPersistence/

Hope this helps!

Regards,

------------------------------------------------------------
Jody Ansley
Web/Application Developer
------------------------------------------------------------
BizNexus
Business Solutions on the Web
Microsoft Certified Solution Provider
Oracle, Cold Fusion, Netscape, Sprint, and IBM Best Partner
------------------------------------------------------------


Mikkel Lauritsen <mlaur...@usa.net> wrote in message news:3810618C...@usa.net...

Mikkel Lauritsen

unread,
Oct 25, 1999, 3:00:00 AM10/25/99
to
Jody Ansley wrote:

> To my understanding, the built-in ASP Session object
> will only store objects if they are apartment-threaded
> or both-threaded (although storing anything in Session
> scope is a scalability no-no).
>
> Objects created from VBScript Classes are not actually
> instances of compiled code. Instead, they are instances
> of a Class. So I don't think they are threaded at all.
> (...Or if they are threaded, I don't know what threading
> model they use.)
>
> If you're trying to persist the data in your classes
> from one ASP page to the next, try some of the methods
> in this article:
>
> http://www.aspzone.com/articles/jody/PseudoPersistence/
>
> Hope this helps!

You bet - thank you very much for the article pointer.

Mikkel Lauritsen

Michael Harris

unread,
Oct 25, 1999, 3:00:00 AM10/25/99
to
There's also an article in the November 1999 issue of MIND on VBScript 5.0 classes (written by Eric Lippert in the MS Scripting Dev group) that specifically says that you _can't_ store vbscript class based objects beyond page level scope.

--
Michael Harris
Jody Ansley <cybe...@msn.com> wrote in message news:O9ROlTPH$GA.249@cppssbbsa05...

------------------------------------------------------------

Hi there...

I've been in your shoes and I had a frustrating time
before I learned that one simply cannot put objects
instantiated from VBScript Classes in Session scope.

To my understanding, the built-in ASP Session object
will only store objects if they are apartment-threaded
or both-threaded (although storing anything in Session
scope is a scalability no-no).

Objects created from VBScript Classes are not actually
instances of compiled code. Instead, they are instances
of a Class. So I don't think they are threaded at all.
(...Or if they are threaded, I don't know what threading
model they use.)

If you're trying to persist the data in your classes
from one ASP page to the next, try some of the methods
in this article:

http://www.aspzone.com/articles/jody/PseudoPersistence/

Hope this helps!

0 new messages