Results 1 to 11 of 11

Thread: [Partially Resolved] Damm logic!

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Thumbs up [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:
    1. Public Main_HDD
    2.  
    3. Public Sub Save_Options(Company_Name As String, Program_Name As String, Key_ As String, Option_ As String, Optional Value_ As String = "")
    4.  
    5. Dim FileStr As String
    6. Dim File_Sav As String
    7. Dim ColsX() As String
    8. Dim RowsX() As String
    9. Dim DataX() As String
    10.  
    11. On Error Resume Next
    12.  
    13. Open Main_HDD & "\Program Settings\" & Company_Name & "\" & Program_Name & "\" & Key_ & ".ini" For Input As #1
    14. Line Input #1, FileStr
    15. Close #1
    16.  
    17. DataX() = Split(FileStr, "|X_=Data=_X|", -1, vbTextCompare)
    18.  
    19. RowsX() = Split(DataX(1), "|X_=Row=_X|", -1, vbTextCompare)
    20.  
    21. If UBound(DataX) < 0 Then
    22. Create_New_File Company_Name, Program_Name, Key_
    23. FileStr = "|X_=Data=_X|" & " " & "|X_=Row=_X|"
    24. GoTo Data_1
    25. End If
    26.  
    27. Dim I As Integer
    28.  
    29. If UBound(RowsX) = 0 Then GoTo Data_1
    30.  
    31. For I = 0 To UBound(RowsX)
    32. MsgBox RowsX(I)
    33. ColsX() = Split(RowsX(I), "|X_=Column=_X|", -1, vbTextCompare)
    34. If ColsX(0) = Option_ Then GoTo Exit_For
    35. Next I
    36.  
    37. Data_1:
    38.  
    39. File_Sav = FileStr & Option_ & "|X_=Column=_X|" & Value_ & "|X_=Row=_X|"
    40. MsgBox File_Sav
    41. GoTo Write_1
    42.  
    43. Exit_For:
    44.  
    45. File_Sav = Replace(FileStr, Option_ & "|X_=Column=_X|" & ColsX(1), Option_ & "|X_=Column=_X|" & Value_)
    46.  
    47. Write_1:
    48.  
    49. Open Main_HDD & "\Program Settings\" & Company_Name & "\" & Program_Name & "\" & Key_ & ".ini" For Output As #1
    50. Print #1, File_Sav
    51. Close #1
    52.  
    53. End Sub
    54.  
    55.  
    56.  
    57. Public Sub Create_New_File(Company_Name As String, Program_Name As String, Key_ As String)
    58.  
    59. On Error Resume Next
    60.  
    61. Dim File_Sav As String
    62.  
    63. File_Sav = "|X_=Data=_X|" & " " & "|X_=Row=_X|"
    64.  
    65. Open Main_HDD & "\Program Settings\" & Company_Name & "\" & Program_Name & "\" & Key_ & ".ini" For Output As #1
    66. Print #1, File_Sav
    67. Close #1
    68.  
    69. End Sub
    70.  
    71.  
    72. Public Sub Do_Variables() 'This is called in sub main
    73.  
    74. Main_HDD = Environ("SystemDrive")
    75.  
    76. 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.
    Last edited by Slyke; Nov 25th, 2006 at 02:10 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width