[Partially Resolved] Damm logic!
Hey, i have no idea why this code doesn't want to work...
What it's suposed to do is mimic the SaveSettings generic function in VB.
Except this time it saves it into a file. I know it's just the way i'm thinking about it, but for the life of me i just can't figure it out.
It should work as such:
1. Open File, if it doesn't exist, call the Create_File sub
2. Check if the Option is there, if not create a new line and go to step 4
3. If it is there, then use the replace command to replace the VALUE and not the OPTION (the entire file gets replaced, but only the VALUE of the OPTION would be changed).
4. Write and save the file.
Here's how i constructed the file:
|X_=Data=_X| = Start of the file.
|X_=Row=_X| = Start of a new row
|X_=Column=_X| = Splits the OPTION from the VALUE
Here's a sample of what SHOULD happen:
|X_=Data=_X|
|X_=Row=_X|Form1.Left|X_=Column=_X|1990
|X_=Row=_X|Form1.Top|X_=Column=_X|5010
|X_=Row=_X|Text1.Text|X_=Column=_X|Hello Everyone!
It should extract something like if i were to load it (which i havent started to create yet):
Form1.Left = 1990
Form1.Top = 5010
Text1.Text = "Hello Everyone!"
And now for my code!
VB Code:
Public Main_HDD
Public Sub Save_Options(Company_Name As String, Program_Name As String, Key_ As String, Option_ As String, Optional Value_ As String = "")
Dim FileStr As String
Dim File_Sav As String
Dim ColsX() As String
Dim RowsX() As String
Dim DataX() As String
On Error Resume Next
Open Main_HDD & "\Program Settings\" & Company_Name & "\" & Program_Name & "\" & Key_ & ".ini" For Input As #1
Line Input #1, FileStr
Close #1
DataX() = Split(FileStr, "|X_=Data=_X|", -1, vbTextCompare)
RowsX() = Split(DataX(1), "|X_=Row=_X|", -1, vbTextCompare)
If UBound(DataX) < 0 Then
Create_New_File Company_Name, Program_Name, Key_
FileStr = "|X_=Data=_X|" & " " & "|X_=Row=_X|"
GoTo Data_1
End If
Dim I As Integer
If UBound(RowsX) = 0 Then GoTo Data_1
For I = 0 To UBound(RowsX)
MsgBox RowsX(I)
ColsX() = Split(RowsX(I), "|X_=Column=_X|", -1, vbTextCompare)
If ColsX(0) = Option_ Then GoTo Exit_For
Next I
Data_1:
File_Sav = FileStr & Option_ & "|X_=Column=_X|" & Value_ & "|X_=Row=_X|"
MsgBox File_Sav
GoTo Write_1
Exit_For:
File_Sav = Replace(FileStr, Option_ & "|X_=Column=_X|" & ColsX(1), Option_ & "|X_=Column=_X|" & Value_)
Write_1:
Open Main_HDD & "\Program Settings\" & Company_Name & "\" & Program_Name & "\" & Key_ & ".ini" For Output As #1
Print #1, File_Sav
Close #1
End Sub
Public Sub Create_New_File(Company_Name As String, Program_Name As String, Key_ As String)
On Error Resume Next
Dim File_Sav As String
File_Sav = "|X_=Data=_X|" & " " & "|X_=Row=_X|"
Open Main_HDD & "\Program Settings\" & Company_Name & "\" & Program_Name & "\" & Key_ & ".ini" For Output As #1
Print #1, File_Sav
Close #1
End Sub
Public Sub Do_Variables() 'This is called in sub main
Main_HDD = Environ("SystemDrive")
End Sub
My code is a bit wacked and stuff, but it's because i've been trouble shooting and testing, it has been cleaned up pretty good, but still.
Re: [Partially Resolved] Damm logic!
It would also help if you were to explain exactly what "doesn't want to work".
Re: [Partially Resolved] Damm logic!
Since there's nesting, I would store the settings in an XML file and use the MSXML parser.