PDA

View Full Version : Maintaining a lisp variable between sessions


anderson.scottglen
2007-07-13, 06:37 PM
I've created a lisp that will, when executed, backup a network drawing to a mirror path on the C drive with a timestamp in the filename which enables incremental backups. To avoid abuse, it also checks the directory to see if a previous backup has been created within the past 2 hours. If it finds such a drawing, the program exits and will not back up (of course there is a command to force a backup if needed, but that is not related to my question)

A friend of mine would like to use this as well but would like to use a value other than 2 hours. I could copy the file and alter the backup check time for him, but that is a poor solution in my mind. This potentially could be used by my office (and perhaps the company with enough fine tuning) from a centralized network location and that solution would no longer be viable. Were I to use a global variable, a user would have to constantly be changing from the default, either per session or per drawing depending on their settings. This would be exceedingly annoying.

So, going beyond local and global variables, is the next step to assign a registry key? I am an amateur programmer at best and this is far beyond my comfort zone. I am looking for advice in this matter. More background: I am a CAD tech, not an employed programmer or CAD manager. I only know lisp/Vlisp, so if it couldn't be accomplished by these means it's probably beyond my immediate skill.

Should I shy away from this territory? Or is this something I could learn to do in half a day or less?

dgorsman
2007-07-13, 07:04 PM
The traditional low-tech means is to use an ASCII configuration file, typically with a .cfg extension. Have a look at the lisp functions for reading and writing to text files.

Using the registry is the next step up, and is typically used in professional or large scale applications. Before using registry keys, make sure you understand the various sections of the system registry, how they are accessed, and what the effect of different users on the computer will be.

Above all, the first thing to do before a single line of code is written, is to plan out the program flow. Make sure you know what is being done, what its being done to, and when; this will help you determine in advance what the major error conditions will be and how to prevent them from causing problems.

rkmcswain
2007-07-13, 08:12 PM
Reading the registry - start of the program
First, set a default value, then try to read the registry. If you get a valid return use it, otherwise, use the default

Writing the registry - end of the program
Write the value out.

Examples of both below.


;; ************* READ ***************
;;Set a default value
(setq val 2.00)
;; Attempt to read the registry value
(setq tmp (vl-registry-read "HKEY_CURRENT_USER\\Software\\anderson\\" "MyVal"))
;; If that was successful, then apply it
;; if not, use the default
(if tmp
(setq realval (atof tmp))
(setq realval val)
)

;; ************* WRITE ***************
(if (eq (type realval) 'REAL)
(vl-registry-write "HKEY_CURRENT_USER\\Software\\anderson\\" "MyVal" (rtos realval 2 2))
)

anderson.scottglen
2007-07-16, 10:13 PM
I really like the "low-tech" solution and I will try that first. Thanks to both of you!