Advice regarding use of Public Shared variables

Advice regarding use of Public Shared variables

tcorey
Mentor Mentor
487 Views
3 Replies
Message 1 of 4

Advice regarding use of Public Shared variables

tcorey
Mentor
Mentor

I have several variables I want to be able to set and then use throughout my project. I can think of two ways to do this, but I don't know which would be best.

 

First, and seems simplest, would be to just Public Shared the variables. Set them as required, call them when needed.

 

Second would be to create an object and assign the variables as properties to that object. It would take more programming to do this option. The beauty of this would be that I could store the values from drawing session to drawing session and would not have to ask the user for the values every time he starts my program. Can this be a custom dictionary object? Is that how you would design it?

 

Unless there is a way to make my Public Shared variables hold their values when the drawing is closed. Static doesn't seem to work here, but I could be missing something.

 

Thanks if you can help,

 

Tim

 



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Platinum Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
0 Likes
488 Views
3 Replies
Replies (3)
Message 2 of 4

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> Unless there is a way to make my Public Shared variables hold their values when the drawing is closed

In my understanding the word "variable" is a name as a placeholder for storing data/value/object/adress in memory ... not in a file. That said it makes the biggest difference if you need the value to be stored with each drawing or you need it just in memory and the values can get lost e.g. when you close AutoCAD.

 

"Public" in a modul or "Public Shared" in a class/class-instance makes no difference, a value you store into it is global for your complete VBA-project. If you want to have a variable for each drawing you should create classes and create an instance from the class-definition for each drawing. Then you should not use the "Shared" phrase as this would not be individual by instance.

 

HTH, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 4

arcticad
Advisor
Advisor

If your intent is to store a variable in the drawing then you best option is to use a custom dictionary to store the value locally into the drawing or store the value into the registry.

---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 4 of 4

tcorey
Mentor
Mentor

Thanks. That's good advice.



Tim Corey
MicroCAD Training and Consulting, Inc.
Redding, CA
Autodesk Platinum Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
0 Likes