Storing program defaults

Storing program defaults

Anonymous
Not applicable
238 Views
4 Replies
Message 1 of 5

Storing program defaults

Anonymous
Not applicable
Hello!

What would be the most elegant way to store and retrieve program
parameters for a custom VBA application? I need to set up defaults for a
number of real, integer and string values for my application and show
the defaults if they have not been set yet. At the end of the session, I
would like to store these on the disk somewhere (INI Text Files?,
Registry?) but not within the DWG file.

Any pointers of what would be a professional way to handle this is
appreciated.

Thanks
Rakesh
-----------------------------------------------
Four Dimension Technologies, Singapore

TechCenter URL: http://www.4d-technologies.com/techcenter
Home Page URL : http://www.4d-technologies.com
Member of the Autodesk Developer Network(ADN)
------------------------------------------------
0 Likes
239 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
>> not in the Drawing....
So, the Dictionary and Xdata is out from your list.
I am using Xdict and Xdata to send variables between Lisp and VBA
btw: I learned these from Joe Sutphin..... Thanks Joe if you are reading
this Email
>> Text File?
For me I just hate it, because anybody can open up the text file.(what do
you think?)
>> Registry?
I am doing it noe for the smaller data size.(Am I right?)

thanks
amy

Rakesh Rao wrote in message <[email protected]>...
>Hello!
>
>What would be the most elegant way to store and retrieve program
>parameters for a custom VBA application? I need to set up defaults for a
>number of real, integer and string values for my application and show
>the defaults if they have not been set yet. At the end of the session, I
>would like to store these on the disk somewhere (INI Text Files?,
>Registry?) but not within the DWG file.
>
>Any pointers of what would be a professional way to handle this is
>appreciated.
>
>Thanks
>Rakesh
>-----------------------------------------------
> Four Dimension Technologies, Singapore
>
>TechCenter URL: http://www.4d-technologies.com/techcenter
>Home Page URL : http://www.4d-technologies.com
>Member of the Autodesk Developer Network(ADN)
>------------------------------------------------
>
0 Likes
Message 3 of 5

Anonymous
Not applicable
Hi Rakesh,

There are 2 places, where you could store such information.
1. Registry
You will have to use the Win32API to read and write to the registry. Or you
could utilize the Lisp functions such as 'Setenv' & 'Getenv' as shown
below:
Dim old_value As String
Dim tmp As String

'Store the existing value in a variable.
old_value = ThisDrawing.GetVariable("USERS1")

'Write Data1 = 3.1415 into the registry under the following path

'HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R15.0\ACAD-1:409\FixedProfile\G
eneral
ThisDrawing.SendCommand "(setenv ""Data1"" ""3.1415"") "

'Read Data1 from the registry and assign it to USERS1.
ThisDrawing.SendCommand "(setvar ""users1"" (getenv ""Data1"")) "

'Read the value from USERS1
tmp = ThisDrawing.GetVariable("USERS1")

'Display the value
MsgBox tmp

'Assign the orginal value back to USERS1.
ThisDrawing.SetVariable "USERS1", old_value

2. Text file - Acad.cfg
AutoCAD maintains a CFG file in which there is room to save application
data
under the [AppData] section. 'Setcfg' & 'Getcfg' are specific functions in
Lisp
(not in VBA) to read and write data to this section as shown below:
Dim old_value As String
Dim tmp As String

'Store the existing value in a variable.
old_value = ThisDrawing.GetVariable("USERS1")

'Write Data1 = 3.1415 into the cfg file under the [AppData] section
ThisDrawing.SendCommand "(setcfg ""AppData/Data1"" ""3.1415"") "

'Read Data1 from the cfg file and assign it to USERS1.
ThisDrawing.SendCommand "(setvar ""users1"" (getcfg ""AppData/Data1"")) "

'Read the value from USERS1
tmp = ThisDrawing.GetVariable("USERS1")

'Display the value
MsgBox tmp

'Assign the orginal value back to USERS1.
ThisDrawing.SetVariable "USERS1", old_value

For details on the following, please refer the online documentation
Setenv, Getenv, Setcfg, Getcfg

Cheers,
Thilak

Rakesh Rao wrote in message
news:[email protected]...
> Hello!
>
> What would be the most elegant way to store and retrieve program
> parameters for a custom VBA application? I need to set up defaults for a
> number of real, integer and string values for my application and show
> the defaults if they have not been set yet. At the end of the session, I
> would like to store these on the disk somewhere (INI Text Files?,
> Registry?) but not within the DWG file.
>
> Any pointers of what would be a professional way to handle this is
> appreciated.
>
> Thanks
> Rakesh
> -----------------------------------------------
> Four Dimension Technologies, Singapore
>
> TechCenter URL: http://www.4d-technologies.com/techcenter
> Home Page URL : http://www.4d-technologies.com
> Member of the Autodesk Developer Network(ADN)
> ------------------------------------------------
>
0 Likes
Message 4 of 5

Anonymous
Not applicable
Hi Rakesh,
I was faced with the same decision a few months ago. After considering ini
files, the registry, and database, I chose to go with an Access database. I
wrote a class to manipulate the user settings from the database. When a
user setting is first called for by the code (i.e..
clsUserSetting.GetUserSetting("11x17_Printer") ) It loads the settings from
database into a global array. (This allows faster access to the settings in
subsequent calls) When the Acad session closes, or when the code calls the
function, the database is updated to the new values if they have changed.
This method has working well for us, and I have not had any problems come up
since I implemented it several months ago. (We are using it on about 10
computers.)
Hope this helps,

-Adam

"Rakesh Rao" wrote in message
news:[email protected]...
> Hello!
>
> What would be the most elegant way to store and retrieve program
> parameters for a custom VBA application? I need to set up defaults for a
> number of real, integer and string values for my application and show
> the defaults if they have not been set yet. At the end of the session, I
> would like to store these on the disk somewhere (INI Text Files?,
> Registry?) but not within the DWG file.
>
> Any pointers of what would be a professional way to handle this is
> appreciated.
>
> Thanks
> Rakesh
> -----------------------------------------------
> Four Dimension Technologies, Singapore
>
> TechCenter URL: http://www.4d-technologies.com/techcenter
> Home Page URL : http://www.4d-technologies.com
> Member of the Autodesk Developer Network(ADN)
> ------------------------------------------------
>
0 Likes
Message 5 of 5

Anonymous
Not applicable
I usually utilize the GetSetting and SaveSetting functions in VB & VBA.
These store your registry entries in a section specifically set aside in the
registry for Visual Basic programs. The key it writes to looks like :

HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Your Program\Your Key

The syntax for GetSetting is - GettSetting(appname, section, key[, default])
0 Likes