![]() |
How to create Singleton Pattern in VBA?
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 |
How to create Singleton Pattern in VBA?
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" wrote in message oups.com... 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 |
All times are GMT +1. The time now is 01:32 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com