Very confused on Loading/saving settings into INI files..

kmorris1186
kmorris1186 used Ask the Experts™
on
I have seen about 5 other posts on how to do this, but i cant figure it out.  I am working on a backup program.  I need to load just 2 values from an INI file. the Directory to Backup and the Destination Dir.  So far all i have is the code to do the back up.. nothing on the saving/loading settings...

I want the user to be able to type the directorys into a text box, then hit the Save button to but those values into a variable (to be used on this run) and then save them to be used later (a restore defaults button too, if it is not too hard.)  

The two variables i need loaded are

varBackupPath 'Directory to be backed up
varDestPath   'Directory backups will be backed up too

Thanks..
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
For just 2 Entries you can use the registry :

To Load:
SaveDir = GetSetting("Toolname", "General", "saveDir")
To save:
SaveSetting "Toolname", "General", "savedir", Dir1.Path

Author

Commented:
I just didnt want to mess with the registry..
i will try it out ..

Author

Commented:
I just didnt want to mess with the registry..
i will try it out ..
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Sorry about that 2nd post...

Cant get it to work...
getting to frustrated to work on it anymore today..
maybe i just need to read more before trying to program..

will try again tomarrow...

i will let you know..

Commented:
The code i gave you assumed that you have a Dir1 Directory control on the form where you run the code...

Add one and it will work..

Or exchange dir1.path with something like "c:\test" (with quotes...

Commented:
You might try the following (it comes from older VB-Versions where you couldn't use the registry):

Create a new module, containing the following code:

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long

Private 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


Sub WriteIni(strFile$, strSection$, strKey$, strValue$)
WritePrivateProfileString strSection, strKey, strValue, strFile
End Sub



Function GetIni(strFile$, strSection$, strKey$) As String
Dim Temp$, Length As Long
Temp = Space$(255)
   
Length= GetPrivateProfileString(strSection, strKey, "", Temp, Len(Temp), strFile)
   
GetIni = Left$(Temp, Length)
End Function




The parameters should be self-explaining. Just be sure to enter the File-Parameter with the full path. If the file doesn't exist, WriteIni will create it. The parameters strSection and strKey you can choose as you want, just be sure to use the same fopr read and write ;-)).

Author

Commented:
well, they way i finally got it to work.. is just read from a text file using the FSO and a textstream.

Author

Commented:
thanks man...

I would rather use INI files so that i can just read a MASTER INI from our bin dir, but this helps..

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial