Storing Program Settings

V

Vince

Hello,

I have around 30 (at most) text boxes and combo boxes that have settings
which need to be stored and restored when the program starts. (This is a VBA
program but I think, it also applies to VB). In the future, many more
settings could be added and they would also have to be saved and loaded
(like a template a program uses for different conditions). I am not sure
about the best way to go about this that could save coding in the long run.
I wanted to write a text file like:

Condition1;Value1;Value2;Value3
Condition2;Value1;Value2;Value3
Condition3;Value1;Value2;Value3

and when loading this file, to load (say) the first three textboxes with
their corresponding values, I would split each line and check the condition
and populate the textboxes / comboboxes. Is this the best way to do this?

Thank you for your time / responses.

Vince
 
M

Mike Harrington

Depending on your needs a simple flat text file that is CSV or TAB
deliminated should work nicely, or if you don't want to bother with file IO
(something that might be less than ideal if it's a macro) you could always
save the information to the registry. Optionally you could always save it
in INI file format or XML format if you need it to be a bit more robust.
Using a flat text file like you mentioned would probably be the best/easiest
choice though.
 
V

Vince

Thanks Mike.

INI seems much easier. I just looked it up and found the following. Is there
such a thing defined for XML as well? A function that would return the
immediate root element and so forth? Would be cool to have an XML because I
could write a DTD to validate it. Also, I hear XML could be made secure. I
am not sure how though.
Public Declare Function GetPrivateProfileString Lib "kernel32" _

Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _

lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As _

String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Dim LReturn As Long

Dim Suse1 As String

Dim sRetBuf As String

Dim iLenBuf As Integer

sRetBuf$ = String$(256, 0)

iLenBuf% = Len(sRetBuf$)

LReturn = GetPrivateProfileString("Settings", "dude", "", sRetBuf$,
iLenBuf%, "c:\replicator\Settings.ini")

Suse1 = Left$(sRetBuf, LReturn)

msgbox(suse1) ' Prints Ain't it a lovely day

[Settings]

dude=Ain't it a lovely day
 
M

Mike Harrington

For XML you would have to use one of the MSXML libraries which would have to
be installed on the client's computer. Almost everyone has at least one
version running, but may not necessarily have the latest and greatest
(depends on the OS and what software they have installed). Generally I have
found use the least possible version (Windows 2000 and above comes with
MSXML 2.0). They're not as easy to work with as INI files, but once you get
used to it, it can be very powerful.

Vince said:
Thanks Mike.

INI seems much easier. I just looked it up and found the following. Is there
such a thing defined for XML as well? A function that would return the
immediate root element and so forth? Would be cool to have an XML because I
could write a DTD to validate it. Also, I hear XML could be made secure. I
am not sure how though.
Public Declare Function GetPrivateProfileString Lib "kernel32" _

Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal _

lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As _

String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Dim LReturn As Long

Dim Suse1 As String

Dim sRetBuf As String

Dim iLenBuf As Integer

sRetBuf$ = String$(256, 0)

iLenBuf% = Len(sRetBuf$)

LReturn = GetPrivateProfileString("Settings", "dude", "", sRetBuf$,
iLenBuf%, "c:\replicator\Settings.ini")

Suse1 = Left$(sRetBuf, LReturn)

msgbox(suse1) ' Prints Ain't it a lovely day

[Settings]

dude=Ain't it a lovely day


Mike Harrington said:
Depending on your needs a simple flat text file that is CSV or TAB
deliminated should work nicely, or if you don't want to bother with file IO
(something that might be less than ideal if it's a macro) you could always
save the information to the registry. Optionally you could always save it
in INI file format or XML format if you need it to be a bit more robust.
Using a flat text file like you mentioned would probably be the best/easiest
choice though.

a
VBA
 
V

Vince

Thanks for the info Mike. I'll stick with INI for now and read up on the XML
library for a future project. From the trends I observe, I think everything
in the future will be based on XML. I've also heard that the new version of
Windows (think it's 2005) uses XML libraries instead of the usual registry.

Vince

Mike Harrington said:
For XML you would have to use one of the MSXML libraries which would have to
be installed on the client's computer. Almost everyone has at least one
version running, but may not necessarily have the latest and greatest
(depends on the OS and what software they have installed). Generally I have
found use the least possible version (Windows 2000 and above comes with
MSXML 2.0). They're not as easy to work with as INI files, but once you get
used to it, it can be very powerful.

Vince said:
Thanks Mike.

INI seems much easier. I just looked it up and found the following. Is there
such a thing defined for XML as well? A function that would return the
immediate root element and so forth? Would be cool to have an XML
because
I
could write a DTD to validate it. Also, I hear XML could be made secure. I
am not sure how though.
Public Declare Function GetPrivateProfileString Lib "kernel32" _

Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String,
ByVal
_

lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As _

String, ByVal nSize As Long, ByVal lpFileName As String) As Long

Dim LReturn As Long

Dim Suse1 As String

Dim sRetBuf As String

Dim iLenBuf As Integer

sRetBuf$ = String$(256, 0)

iLenBuf% = Len(sRetBuf$)

LReturn = GetPrivateProfileString("Settings", "dude", "", sRetBuf$,
iLenBuf%, "c:\replicator\Settings.ini")

Suse1 = Left$(sRetBuf, LReturn)

msgbox(suse1) ' Prints Ain't it a lovely day

[Settings]

dude=Ain't it a lovely day


Mike Harrington said:
Depending on your needs a simple flat text file that is CSV or TAB
deliminated should work nicely, or if you don't want to bother with
file
IO
(something that might be less than ideal if it's a macro) you could always
save the information to the registry. Optionally you could always
save
is
 
R

Ralph

Vince said:
Thanks for the info Mike. I'll stick with INI for now and read up on the XML
library for a future project. From the trends I observe, I think everything
in the future will be based on XML. I've also heard that the new version of
Windows (think it's 2005) uses XML libraries instead of the usual registry.

Vince

I have also heard that XML is going to replace SQLServer, Oracle and DB2. It
is going to be the primary media for all HiDef Wireless services, and will
eventually extend our lifetimes beyond 100+ years.

But then I don't necessary believe everything I hear.

-ralph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top