Visual Basic Customization

Visual Basic Customization

Reply
*Expert Elite*
tcorey
Posts: 2,642
Registered: ‎12-18-2002
Message 1 of 4 (110 Views)

Advice regarding use of Public Shared variables

110 Views, 3 Replies
05-03-2012 12:26 AM

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, Owner
Delta Engineering Systems
Redding, CA
Autodesk Authorized Value-Added Reseller
*Expert Elite*
Alfred.NESWADBA
Posts: 9,216
Registered: ‎06-29-2007
Message 2 of 4 (100 Views)

Re: Advice regarding use of Public Shared variables

05-03-2012 01:17 PM 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
-------------------------------------------------------------------------
*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 3 of 4 (83 Views)

Re: Advice regarding use of Public Shared variables

05-08-2012 03:14 AM 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))
*Expert Elite*
tcorey
Posts: 2,642
Registered: ‎12-18-2002
Message 4 of 4 (79 Views)

Re: Advice regarding use of Public Shared variables

05-08-2012 10:56 AM in reply to: tcorey

Thanks. That's good advice.

Tim Corey, Owner
Delta Engineering Systems
Redding, CA
Autodesk Authorized Value-Added Reseller
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.