?
Solved

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

Posted on 1999-11-15
13
Medium Priority
?
149 Views
Last Modified: 2011-09-20
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
0
Comment
Question by:tlaks
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2208639
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..
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2208656
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!
0
 

Expert Comment

by:moterk
ID: 2208904
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.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Author Comment

by:tlaks
ID: 2209076
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.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2209108
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!
0
 

Author Comment

by:tlaks
ID: 2209132
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?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2209139
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!


0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2209152
You can at any time during run-time check the value of App.Path to see where your exe-file is.
0
 

Author Comment

by:tlaks
ID: 2211299
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.
0
 
LVL 7

Expert Comment

by:Vbmaster
ID: 2211985
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?).
0
 

Author Comment

by:tlaks
ID: 2212014
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.
0
 
LVL 7

Accepted Solution

by:
Vbmaster earned 400 total points
ID: 2212161
And here comes a 'answer'..
0
 

Author Comment

by:tlaks
ID: 2212168
Thanks.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month5 days, 10 hours left to enroll

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question