VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Advice regarding use of Public Shared variables

3 REPLIES 3
Reply
Message 1 of 4
tcorey
285 Views, 3 Replies

Advice regarding use of Public Shared variables

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 Gold Reseller

New knowledge is the most valuable commodity on earth. -- Kurt Vonnegut
3 REPLIES 3
Message 2 of 4
Alfred.NESWADBA
in reply to: tcorey

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
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 4
arcticad
in reply to: tcorey

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))
Message 4 of 4
tcorey
in reply to: tcorey

Thanks. That's good advice.



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

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost