Hello.
I have created a class names MainSettings it contains a list of properties I want to set and use in my application.
In my App.Open I instantiate
Dim SOPSettings as New MainSettings
When I open my Setting Window, I want to reference the SOPSettings. and that is not available.
Am I using the class incorrectly? Guidance and advice appreciated.
Robb
Sounds like you need to set SOPSettings as a global property and then change app.open to:
OPSettings = New MainSettings
You need to keep the instance of the class available somewhere to be accessed. The way you’ve coded, SOPSettings
goes out of scope at the end of App.Open
The most generic suggestion would be to use a globals module with a property for oSOPSettings
, and in App.Open
instantiate it with something along the lines of modGlobals.oSOPSettings = new clsMainSettings
Edit: D’oh beaten by seconds
[quote=341014:@Tim Parnell]You need to keep the instance of the class available somewhere to be accessed. The way you’ve coded, SOPSettings
goes out of scope at the end of App.Open
The most generic suggestion would be to use a globals module with a property for oSOPSettings
, and in App.Open
instantiate it with something along the lines of modGlobals.oSOPSettings = new clsMainSettings
Edit: D’oh beaten by seconds[/quote]
Is there a best practice to add the property to a module versus to the App level in open? i.e
SOPSettings = new MainSettings
Depends on how you will be using the instance you have named “SOPSettings”. The rule of thumb is to keep the focus as narrow as possible. If you are using that instance in only 1 window, then instantiate it as a property of the window. If it will truly be used throughout your app, then place it is a “globals” module so it is available to all of your windows. You can also pass the instance you have created as an argument of a method if you just need it briefly elsewhere in your app.