What I am trying to do is allow someone to enter some values into my macro and save the configurations i.e. using an ini file to save and load various configurations for the user.
Example:
[fred] (fred is the config name in the combobox)
username=fred
useremail=[email protected]
[albert] (albert is the config name in the combobox)
username=albert
useremail=[email protected]
They get a screen, input the data and it saves it in the ini. I am using a combobox to let them go back and select the saved entry to load it. I have that all down and good... however...
If they want to remove [fred] from the ini file, how could I do that? Also, would like to have the label removed from the combobox too... ie. remove "fred"
Deleting Portion of ini file
Moderators: Dorian (MJT support), JRL
You could use the "ReadLn" function to read each individual line of the INI file then use the "WriteLn" function to write each line to a new temporary file. When the line with the section header you're looking for comes up, stop writing until the next section header is read, then write the rest of the INI file to the temporary file. Then, just to be on the safe side rename the INI file to a backup file name or location. Then rename and/or move the temporary file to the INI file name and location.
Something like this:(untested)
Let>k=0
Label>start
Let>k=k+1
ReadLn>C:\path\file.ini,%k%,line
If>line=##EOF##,finish
If>line=[fred],stopwriting
Label>startwriting
WriteLn>C:\path\tempfile.tmp,wresult,%line%
goto>start
Label>stopwriting
Let>k=k+1
ReadLn>C:\path\file.ini,%k%,line
If>line=##EOF##,finish
Midstr>%line%,1,1,result
If>result=[,startwriting,stopwriting
Label>finish
MoveFile>C:\path\file.ini,C:\path\file.bak
MoveFile>C:\path\tempfile.tmp,C:\path\file.ini
Hope this helps,
Dick
Something like this:(untested)
Let>k=0
Label>start
Let>k=k+1
ReadLn>C:\path\file.ini,%k%,line
If>line=##EOF##,finish
If>line=[fred],stopwriting
Label>startwriting
WriteLn>C:\path\tempfile.tmp,wresult,%line%
goto>start
Label>stopwriting
Let>k=k+1
ReadLn>C:\path\file.ini,%k%,line
If>line=##EOF##,finish
Midstr>%line%,1,1,result
If>result=[,startwriting,stopwriting
Label>finish
MoveFile>C:\path\file.ini,C:\path\file.bak
MoveFile>C:\path\tempfile.tmp,C:\path\file.ini
Hope this helps,
Dick
-
- Newbie
- Posts: 10
- Joined: Sun Aug 07, 2005 10:42 am