To save Text1
Quote:
Private Sub WriteConfig
On Error GoTo error
Open "" & App.Path & "\CONFIGNAME.ini" For Output As #1
Print #1, "T=" & Text1.Text & ""
Close #1
Exit Sub
error:
MsgBox "An error occured while writing the config.", vbCritical, "ERROR"
End Sub
|
To read the config and get the content from it.
Quote:
Private Sub ReadConfig()
On Error GoTo error
If Dir("" & App.Path & "\CONFIGNAME.ini") = "" Then
Exit Sub
End If
LineNum = 0
Open "" & App.Path & "\CONFIGNAME.ini" For Input As #1
Do Until EOF(1)
LineNum = LineNum + 1
Line Input #1, ConfigLine
If ConfigLine Like "T=*" Then
Text1.Text = Right(ConfigLine, Len(ConfigLine) - 2)
Else
End If
Loop
Close #1
Exit Sub
error:
MsgBox "An error occured while reading the config.", vbCritical, "Error"
End Sub
|
To add a new line of text in your ini file, just insert this small code in the line that prints what you want the file to say.
So let's say you had three textboxes named Text1, Text2 and Text3.
Quote:
Print #1, "1=" & Text1.Text & vbCrLf & "2=" & Text2.Text & vbCrLf & "3=" & Text3.Text & vbCrLf & ""
|
To add the reading of another line in the config, add another one of these codes to your ReadConfig function.
Quote:
If ConfigLine Like "(whatever)=*" Then
(whatever).Text = Right(ConfigLine, Len(ConfigLine) - 2)
|
To write the config, just insert this code in a command button or some other function.
and to read it,
It's kind of complicated but if you just read everything over and look at what is written you can get the hang of it. I'm far too lazy to explain everything piece by piece, so you'll have to just try and figure it out. :|