PC Review


Reply
Thread Tools Rate Thread

How to create Singleton Pattern in VBA?

 
 
Paul
Guest
Posts: n/a
 
      30th Oct 2006
Hi,

I am a newbie in VBA. This is first time I try to use customer classes
in VBA. I want to know whether it is possible to create Singleton
Pattern in VBA?

For example, in java we can do this:

public class MyClass {
private static MyClass instance;
private MyClass() {}
public static MyClass getInstance() {
if (instance==null)
instance=new MyClass();
return instance;
}
}

Such that we can call: MyClass.getInstance() to retrieve the same
reference all the time.

Does anyone know how to do it in VBA?

Thanks a lot.

Paul

 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      31st Oct 2006
Given that the only types of instancing on VBA classes is Private and
PublicNotCreatable, the WB containing the class could control its creation.
As I understand it, as each instance of the class gets its own local data,
such a concept as below does not exist natively in VBA.

NickHK

"Paul" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I am a newbie in VBA. This is first time I try to use customer classes
> in VBA. I want to know whether it is possible to create Singleton
> Pattern in VBA?
>
> For example, in java we can do this:
>
> public class MyClass {
> private static MyClass instance;
> private MyClass() {}
> public static MyClass getInstance() {
> if (instance==null)
> instance=new MyClass();
> return instance;
> }
> }
>
> Such that we can call: MyClass.getInstance() to retrieve the same
> reference all the time.
>
> Does anyone know how to do it in VBA?
>
> Thanks a lot.
>
> Paul
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
singleton pattern donet programmer Microsoft ASP .NET 11 3rd Nov 2006 08:30 PM
Singleton pattern for the web INeedADip Microsoft C# .NET 7 29th Jan 2006 05:05 PM
Singleton Pattern and Collections =?Utf-8?B?Um9iZXJ0IFcu?= Microsoft C# .NET 13 15th Sep 2005 02:02 AM
The singleton pattern Jonathan Rea Microsoft C# .NET 2 25th Oct 2004 03:54 PM
Should I create my object with singleton pattern? thanks. davidw Microsoft C# .NET 2 3rd Mar 2004 05:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:26 PM.