473,480 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VBScript classes, singletons and Class_Terminate

As you might have gathered from the Subject, I've been experimenting with
using VBScript classes in my ASP pages to tidy the script up. Generally
things are going well.

Since I come from a C++ background, I have long made use of singleton
objects, in various forms, and I can see an obvious use for one here but not
sure if I can. I'll explain the situation:-

I have a cDataLink class, configured via a couple of Const defines for the
Provider type, database name etc (So I can easily set it according to
Access/SQL etc). In addition, all my other classes use 'lazy loading', only
going to a SQL SELECT to get information if they are asked for that data. To
create the cDataLink object, I can see two possibilities.

a) I can create it at the beginning of every page. Setting the object to
Nothing at the end will (I assume) call its Class_Terminate() and allow it
to clean up.

Although this would work, it means that each page will open the data
connection regardless of whether the other objects actually need it. It goes
against the grain of only opening a connection if you have to, and then at
the latest possible moment, especially if it then isn't required for that
particular parsing of the page.

b) Using the abilities provided by a well designed Singleton, the first
object to require the connection would create the cDataLink object by the
very nature of asking for it. Any data connection requests after that point
would return the existing connection object.

The obvious benefit of this is that if no class instance requests the
connection, it will never be created. One problem I foresee is in the
termination of the connection. Unless I actively Set the connection to
Nothing at the end of the page, I'm not sure if I can garantee that the
connection object will be terminated and released. This goes against the
design of a Singleton, which lingers uniquely just as long as it is required
and then goes.

c) Possibly I could do something based round Reference counts, like a COM
object, but that may be code for coding's sake.

On to my questions:-

a) Am I right to worry that a VBS class is not garanteed to call its
Terminate unless it is set to Nothing somewhere, or is it safe to assume it
will vanish when the page has finished parsing, running its Terminate() in
the process.

b) I have yet to find any sort of 'static' declaration for VBS classes
(although I may have been looking in the wrong place). This is almost
obligatory for creating a true Singleton type of object, since its one of
the tricks for ensuring that you will always the same object back.

Basically I'm asking if it is actually possible to create a Singleton class
in VBS (via 'proper' techniques, or by tricks/cheats), and if it is possible
am I stepping into a world of hell trying to accomplish it?

Yours,

A Ratcliffe
ar********@archimagic.net

ps. Sorry about the verbiage. Hazard of the trade at times when you are
trying to describe something.
Jul 19 '05 #1
7 6679
As an addendum, is there any way to do the equivalent of this in an ASP include (used to ensure a header is only included once in C/C++)

#ifndef INC_MYINCLUDE
#define INC_MYINCLUDE

// Whatever you only want including once

#endif

You'll have to excuse the HTML posting (I know plain text is smaller), but wanted to show the code correctly.

Yours,

A Ratcliffe
ar********@archimagic.net

Jul 19 '05 #2
"Mike Moore [MSFT]" wrote:
Hi,

For your first question, VBScript does not have classes the way
javascript has them. You cannot encapsulate groups of methods and
properties into a class.

Huh? Then what is this page talking about:
http://msdn.microsoft.com/library/en...vsstmclass.asp
Jul 19 '05 #3
""Mike Moore [MSFT]"" wrote:

For your first question, VBScript does not have classes the way javascript
has them. You cannot encapsulate groups of methods and properties into a
class.


Not even with the Class Statement?
http://msdn.microsoft.com/library/en...vsstmClass.asp
--
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. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 19 '05 #4
I did wonder what you were talking about, given the fact I'd already been
using classes (as stated in my post)..

Given the fact that we CAN write classes in VBS, does anyone have any
suggestions/answers for my questions?

Yours,

Ann-Marie Ratcliffe
ar********@archimagic.net

""Mike Moore [MSFT]"" <mi****@online.microsoft.com> wrote in message
news:Q$**************@cpmsftngxa06.phx.gbl...
Hi Dave & Bob,

Thank you for correcting me. You've shown me that my knowledge of VBScript
is not as thorough as I had thought. Thank you for the tip.

Thank you, Mike Moore
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
From: "Bob Barrows" <re*******@yahoo.com>
References: <e$**************@TK2MSFTNGP12.phx.gbl>

<OM**************@TK2MSFTNGP12.phx.gbl>
<98**************@cpmsftngxa06.phx.gbl>
Subject: Re: VBScript classes, singletons and Class_Terminate
Date: Tue, 5 Aug 2003 15:21:55 -0400
Lines: 11
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <O3**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.inetserver.asp.general
NNTP-Posting-Host: 63.250.134.34
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.inetserver.asp.general:248695 X-Tomcat-NG: microsoft.public.inetserver.asp.general

"Mike Moore [MSFT]" wrote:
Hi,

For your first question, VBScript does not have classes the way
javascript has them. You cannot encapsulate groups of methods and
properties into a class.

Huh? Then what is this page talking about:
http://msdn.microsoft.com/library/en...vsstmclass.asp

Jul 19 '05 #5
I no longer have your post on my machine. Could you repost it?
Bob Barrows
A Ratcliffe wrote:
I did wonder what you were talking about, given the fact I'd already
been using classes (as stated in my post)..

Given the fact that we CAN write classes in VBS, does anyone have any
suggestions/answers for my questions?

Yours,

Ann-Marie Ratcliffe
ar********@archimagic.net

""Mike Moore [MSFT]"" <mi****@online.microsoft.com> wrote in message
news:Q$**************@cpmsftngxa06.phx.gbl...
Hi Dave & Bob,

Thank you for correcting me. You've shown me that my knowledge of
VBScript is not as thorough as I had thought. Thank you for the tip.

Thank you, Mike Moore
Microsoft, ASP.NET

This posting is provided "AS IS", with no warranties, and confers no
rights.
--------------------
From: "Bob Barrows" <re*******@yahoo.com>
References: <e$**************@TK2MSFTNGP12.phx.gbl>

<OM**************@TK2MSFTNGP12.phx.gbl>
<98**************@cpmsftngxa06.phx.gbl>
Subject: Re: VBScript classes, singletons and Class_Terminate
Date: Tue, 5 Aug 2003 15:21:55 -0400
Lines: 11
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <O3**************@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.inetserver.asp.general
NNTP-Posting-Host: 63.250.134.34
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.inetserver.asp.general:248695 X-Tomcat-NG:
microsoft.public.inetserver.asp.general

"Mike Moore [MSFT]" wrote:
Hi,

For your first question, VBScript does not have classes the way
javascript has them. You cannot encapsulate groups of methods and
properties into a class.

Huh? Then what is this page talking about:
http://msdn.microsoft.com/library/en...vsstmclass.asp

Jul 19 '05 #6
As you might have gathered from the Subject, I've been experimenting with
using VBScript classes in my ASP pages to tidy the script up. Generally
things are going well.

Since I come from a C++ background, I have long made use of singleton
objects, in various forms, and I can see an obvious use for one here but not
sure if I can. I'll explain the situation:-

I have a cDataLink class, configured via a couple of Const defines for the
Provider type, database name etc (So I can easily set it according to
Access/SQL etc). In addition, all my other classes use 'lazy loading', only
going to a SQL SELECT to get information if they are asked for that data. To
create the cDataLink object, I can see two possibilities.

a) I can create it at the beginning of every page. Setting the object to
Nothing at the end will (I assume) call its Class_Terminate() and allow it
to clean up.

Although this would work, it means that each page will open the data
connection regardless of whether the other objects actually need it. It goes
against the grain of only opening a connection if you have to, and then at
the latest possible moment, especially if it then isn't required for that
particular parsing of the page.

b) Using the abilities provided by a well designed Singleton, the first
object to require the connection would create the cDataLink object by the
very nature of asking for it. Any data connection requests after that point
would return the existing connection object.

The obvious benefit of this is that if no class instance requests the
connection, it will never be created. One problem I foresee is in the
termination of the connection. Unless I actively Set the connection to
Nothing at the end of the page, I'm not sure if I can garantee that the
connection object will be terminated and released. This goes against the
design of a Singleton, which lingers uniquely just as long as it is required
and then goes.

c) Possibly I could do something based round Reference counts, like a COM
object, but that may be code for coding's sake.

On to my questions:-

a) Am I right to worry that a VBS class is not garanteed to call its
Terminate unless it is set to Nothing somewhere, or is it safe to assume it
will vanish when the page has finished parsing, running its Terminate() in
the process.

b) I have yet to find any sort of 'static' declaration for VBS classes
(although I may have been looking in the wrong place). This is almost
obligatory for creating a true Singleton type of object, since its one of
the tricks for ensuring that you will always the same object back.

Basically I'm asking if it is actually possible to create a Singleton class
in VBS (via 'proper' techniques, or by tricks/cheats), and if it is possible
am I stepping into a world of hell trying to accomplish it?

Yours,

A Ratcliffe
ar********@archimagic.net

ps. Sorry about the verbiage. Hazard of the trade at times when you are
trying to describe something.

Jul 19 '05 #7
Sorry to say this, but I have no experience using VBS classes, given the
fact that we're still using an earlier version of VBS, so I do not have the
answers to your questions. Hopefully someone else will be able to provide
insight. Michael Harris, who is very active over a m.p.scripting.vbscript
may be able to better answer you.

Bob Barrows

A Ratcliffe wrote:
As you might have gathered from the Subject, I've been experimenting
with using VBScript classes in my ASP pages to tidy the script up.
Generally things are going well.

Since I come from a C++ background, I have long made use of singleton
objects, in various forms, and I can see an obvious use for one here
but not sure if I can. I'll explain the situation:-

I have a cDataLink class, configured via a couple of Const defines
for the Provider type, database name etc (So I can easily set it
according to Access/SQL etc). In addition, all my other classes use
'lazy loading', only going to a SQL SELECT to get information if they
are asked for that data. To create the cDataLink object, I can see
two possibilities.

a) I can create it at the beginning of every page. Setting the object
to Nothing at the end will (I assume) call its Class_Terminate() and
allow it to clean up.

Although this would work, it means that each page will open the data
connection regardless of whether the other objects actually need it.
It goes against the grain of only opening a connection if you have
to, and then at the latest possible moment, especially if it then
isn't required for that particular parsing of the page.

b) Using the abilities provided by a well designed Singleton, the
first object to require the connection would create the cDataLink
object by the very nature of asking for it. Any data connection
requests after that point would return the existing connection object.

The obvious benefit of this is that if no class instance requests the
connection, it will never be created. One problem I foresee is in the
termination of the connection. Unless I actively Set the connection to
Nothing at the end of the page, I'm not sure if I can garantee that
the connection object will be terminated and released. This goes
against the design of a Singleton, which lingers uniquely just as
long as it is required and then goes.

c) Possibly I could do something based round Reference counts, like a
COM object, but that may be code for coding's sake.

On to my questions:-

a) Am I right to worry that a VBS class is not garanteed to call its
Terminate unless it is set to Nothing somewhere, or is it safe to
assume it will vanish when the page has finished parsing, running its
Terminate() in the process.

b) I have yet to find any sort of 'static' declaration for VBS classes
(although I may have been looking in the wrong place). This is almost
obligatory for creating a true Singleton type of object, since its
one of the tricks for ensuring that you will always the same object
back.

Basically I'm asking if it is actually possible to create a Singleton
class in VBS (via 'proper' techniques, or by tricks/cheats), and if
it is possible am I stepping into a world of hell trying to
accomplish it?

Yours,

A Ratcliffe
ar********@archimagic.net

ps. Sorry about the verbiage. Hazard of the trade at times when you
are trying to describe something.


Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2506
by: CJM | last post by:
For the majority of my work, I just use plain ASP. On the rare occasion that I am doing something intensive that does require user interaction I might create a COM component (ie where performance...
16
9311
by: Mike Schinkel | last post by:
Does anyone know if there are bugs in VBScript's GetRef()? I'm using VBScript Version 5.6.8515 on Win2003Server w/ASP. Sometimes it returns an object that VarType() says is a vbObject. Other...
2
5372
by: mike | last post by:
Hi, I'm running into a problem with VBSCRIPT classes in ASP. I use a seperate file for each class I use. Some of these class files are included in multiple ASP scripts, but are also included in...
1
6441
by: | last post by:
I'm going a little crazy trying to learn how to use arrays as properties in VBScript classes. Hopefully someone can help. First, I can't figure out whether it's possible to iterate through the...
1
2407
by: Michael D. Ober | last post by:
Is there anyway to force the equivalent to VB 6's Class_Terminate event when a class object goes out of scope. I have several classes in VB 6 that depend on the Class_Terminate event firing as...
10
2274
by: Noozer | last post by:
I'm writing an ASP application and have a noob question... I have a class that access an MS SQL database. I have another class also accesses an MS SQL database and this second class uses objects...
9
1774
by: Ugur ASLAN | last post by:
Hello, I want to implement a class structure that can take a querystring and the value of querysting can be called as myClass.getQuery("test").value. I know that I can do it like...
4
1318
by: nokia33948 | last post by:
Hi, I have a small big problem with classes and objects.. In VB6 I create a new project, DLL ActiveX; I leave the default name ("progetto1" - in italian); then I rename the class module in...
3
2246
by: ziycon | last post by:
I'm well versed on classes and OOP in PHP and Java but can't for the life of me get it to working in ASP classic using VB. I'm getting no errors, a blank page is displaying. I have the below in...
0
6903
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5318
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4763
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2987
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2974
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
170
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.