Dr. Demento
Well-known Member
- Joined
- Nov 2, 2010
- Messages
- 618
- Office Version
- 2019
- 2016
- Platform
- Windows
I've been using bad programming form for a number of years by using an EXCESSIVE number of global constants (I used to get Out of Memory errors running the smallest sub; it's better now but still happens). After learning about classes, I was able to move the majority of the global constants to my class modules.
However, now every time I want to access anything in those class modules I have to instantiate it first; I've set up two global variables but they don't point to the class until I assign them (I'm explaining myself to people with huge amounts of experience compared to me ). I've tried Set in ThisWorkbook module; nope! I've tried defining them in a commonly used procedures that occur at startup; hard nope! I want to avoid instantiation everywhere the class is used because of the ubiquity of how I was using the global constants; instead, I'd like a one and done.
I found this article (3 Ways to Create Class Instances in VBA) and I think that addresses my problem but being a noob to classes, I'm not entirely sure. I also don't understand the implications of the limitation listed, so if someone could educate me, I'd appreciate it.
I can't use Rubberduck, as I use the class at work.
Thanks, y'all.
However, now every time I want to access anything in those class modules I have to instantiate it first; I've set up two global variables but they don't point to the class until I assign them (I'm explaining myself to people with huge amounts of experience compared to me ). I've tried Set in ThisWorkbook module; nope! I've tried defining them in a commonly used procedures that occur at startup; hard nope! I want to avoid instantiation everywhere the class is used because of the ubiquity of how I was using the global constants; instead, I'd like a one and done.
I found this article (3 Ways to Create Class Instances in VBA) and I think that addresses my problem but being a noob to classes, I'm not entirely sure. I also don't understand the implications of the limitation listed, so if someone could educate me, I'd appreciate it.
I can't use Rubberduck, as I use the class at work.
Thanks, y'all.