Link to home
Start Free TrialLog in
Avatar of tlaks
tlaks

asked on

To save a list, should I use the Registry or a File?

My program utilizes a list stored in an array.  I would like the user to be able to modify the list, and have the changes available the next time the user runs the program.  This program already utilize Registry values for a number of variables.  Should an array of values be saved in the Regisrty?  If so, how?  Bare-in-mind, the number of elements in the array can vary according to what the user enters.  Alternately, should I just write/read the values to/from a file?  Is so, in which directory should I place it?

I am using VB 6.0
Avatar of Vbmaster
Vbmaster

I personally prefer putting larger information in INI files and this INI files is ofcourse put in the application path, I only store the path to where the program is in the registry (that way I give fast access to the settings without havin' to clutter the registry).

Is the array really big? Is it string values or numeric values? One way would be to combine all the strings into one big string delimited with a character (i.e. "|", Tab or whatever character that aint being used in the strings). Then when the program wants to read the values back it reads the whole string and just splits the string..
Well, you could store your array in the registry by having a key for each item and incrementing the key by one each time you store an item in the array.

For example:

Dim X As Variant
Dim Element As Variant
Dim I As Long

X = Array("AAA", "BBB", "CCC")
For Each Element In X

'TO SAVE OFF SETTINGS    SaveSetting "MyApp", "ArrayList", "Item" + Format(I, "00000"), Element
    I = I + 1
Next

'TO GET BACK SETTINGS
X = GetAllSettings("MyApp", "ArrayList")
For I = LBound(X, 1) To UBound(X, 1)
    Debug.Print X(I, 0), X(I, 1)
Next I


Cheers!
I agree with VBmaster!

The registry is big enough without storing array data in it.  It should only be used for minimal essential data.  Store it in a file and put the file name (with path) in the registry.  Since the file name is in the registry you can put the file anywhere you want to.
Avatar of tlaks

ASKER

I anticipate that my array will not be very large, so mcrider's answer appears appealing, however, one requirement I took for granted is to retain the functionality of the default option of GetSetting which is not available in GetAllSettings.

As for VBmaster's comment, (using an INI file) is there a dynamic way for me to determine where my program is running?  Most of my VB apps are used by myself, and I am poorly versed in the process of "Package and Deployment."  Also, I thought that the Registry made INI files passe.  Could you point me to a good reference on how to write to or format INI files.
Well if you want to retain default functionality, you can do it this way:

'TO GET BACK SETTINGS
X = GetAllSettings("MyApp", "ArrayList")
For I = LBound(X, 1) To UBound(X, 1)
    Debug.Print GetSetting("MyApp", "ArrayList", X(I, 0), "DEFAULT")
Next I


Cheers!
Avatar of tlaks

ASKER

My default is an array.  This requires a different value for each array value AND, the number of elements in my original array could vary from what the user enters.  More comments?
Keep a counter when going through the FOR LOOP to get the Default value:


'TO GET BACK SETTINGS
X = GetAllSettings("MyApp", "ArrayList")
J=0
For I = LBound(X, 1) To UBound(X, 1)
    Debug.Print GetSetting("MyApp", "ArrayList", X(I, 0), DefArray(j))
    J=J+1
Next I

Cheers!


You can at any time during run-time check the value of App.Path to see where your exe-file is.
Avatar of tlaks

ASKER

I would like to accept VBmaster's comment of Monday, November 15 1999 - 11:06AM EST as my answer.  I used his second option - I "join" my array into a single string, with a carriage return line feed as the delimiter, and save that to the registry.  This also gives me an easy way to allow my user to modify the array.  After GetSetting, I send the array to a textbox (multiline=true).  For the textbox_change event, I split the textbox.text with carriage/return line feed as the delimiter, and assign it to the array.
If this is the case I think you will need to reject the answer, then ask me to "answer the question" or just accept the comment as a answer (might be that this option is not available when you have a proposed answer?).
Avatar of tlaks

ASKER

I would like to accept VBmaster's comment of Monday, November 15 1999 - 11:06AM EST as my answer.  I used his second option - I "join" my array into a single string, with a carriage return line feed as the delimiter, and save that to the registry.  This also gives me an easy way to allow my user to modify the array.  After GetSetting, I send the array to a textbox (multiline=true).  For the textbox_change event, I split the textbox.text with carriage/return line feed as the delimiter, and assign it to the array.
ASKER CERTIFIED SOLUTION
Avatar of Vbmaster
Vbmaster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tlaks

ASKER

Thanks.