Results 1 to 9 of 9

Thread: * RESOLVED * Saving to an .ini file (not typical format of x=x)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Coventry, England
    Posts
    169

    * RESOLVED * Saving to an .ini file (not typical format of x=x)

    I want to save to a ini file of the following format:

    VB Code:
    1. autoframeskip           1
    2. frameskip               0
    3. waitvsync               0
    4. triplebuffer            0
    5. window                  0
    6. ddraw                   1
    7. direct3d                0
    8. hwstretch               1

    I've saved to typical ini files before using downloadable ReadINI and WriteINI functions, but not with tabbed spacing like this one.

    TIA
    Last edited by seh; Oct 23rd, 2003 at 01:05 PM.

  2. #2

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Coventry, England
    Posts
    169
    It doesn't have to be tabbed I guess, but even then the question remains...

  4. #4
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Unless the user would be looking at the file, I couldn't care less what the data looks like in a file as long as I can get/write data easily.
    Please rate my post.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Coventry, England
    Posts
    169
    Originally posted by Shawn N
    Unless the user would be looking at the file, I couldn't care less what the data looks like in a file as long as I can get/write data easily.
    Indeed. But I still don't know how to save to it The modules I have for saving to ini files, puts in a "=" char. The ini file I want to save to doesn't have this char.

  6. #6

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Coventry, England
    Posts
    169
    OK thanks.

  8. #8
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    You can also use "normal" read and write code against a real ini file, it's just usually more convenient to use things like GetPrivateProfileInt, GetPrivateProfileString and WritePrivateProfileString.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2002
    Location
    Coventry, England
    Posts
    169
    Yeah I'm aware of that. I thought there might have been a module/api to manipulate my file, instead of me coding one myself like I have done ...

    VB Code:
    1. Private Sub WriteMameIni(name As String, spaces As Integer, value As Byte)
    2.     Dim strText As String
    3.     Dim pos As Integer
    4.     Dim counter As Long
    5.     Dim varText As Variant
    6.     Dim Upper As Long
    7.     Dim FileNum As Integer
    8.     Dim arrWrite() As String
    9.     Dim mamePath As String
    10.    
    11.     mamePath = ReadInI("PATHS AND FOLDERS", "mamePath", App.Path & "\mstart.ini")
    12.  
    13.    
    14.     Open mamePath & "\mame.ini" For Input As #1
    15.         strText = Input(LOF(1), #1)
    16.     Close #1
    17.    
    18.    
    19.     varText = Split(strText, vbCrLf)
    20.     Upper = UBound(varText)
    21.     ReDim arrWrite(Upper)
    22.  
    23.     'Read and process all in one go.
    24.     For counter = 0 To Upper - 1
    25.         pos = InStr(1, varText(counter), name)
    26.         If pos <> 0 Then
    27.             varText(counter) = name & Space(spaces) & value
    28.         End If
    29.         arrWrite(counter) = varText(counter)
    30.     Next
    31.    
    32.    
    33.     FileNum = FreeFile
    34.     Open "d:\emu\mame\mame.ini" For Output As #FileNum
    35.  
    36.     'Write all in one go.
    37.     For counter = 0 To Upper - 1
    38.         Print #FileNum, arrWrite(counter)
    39.     Next
    40.    
    41.     Close #FileNum
    42. End Sub
    43.  
    44. Private Function ReadMameIni(name As String)
    45.     Dim strText As String
    46.     Dim pos As Integer
    47.     Dim counter As Long
    48.     Dim varText As Variant
    49.     Dim Upper As Long
    50.     Dim mamePath As String
    51.    
    52.     mamePath = ReadInI("PATHS AND FOLDERS", "mamePath", App.Path & "\mstart.ini")
    53.  
    54.    
    55.     Open mamePath & "\mame.ini" For Input As #1
    56.         strText = Input(LOF(1), #1)
    57.     Close #1
    58.    
    59.    
    60.     varText = Split(strText, vbCrLf)
    61.     Upper = UBound(varText)
    62.     ReDim arrWrite(Upper)
    63.  
    64.     For counter = 0 To Upper - 1
    65.         pos = InStr(1, varText(counter), name)
    66.         If pos <> 0 Then
    67.             varText(counter) = Mid(varText(counter), Len(name) + 1)
    68.             ReadMameIni = Trim(varText(counter))
    69.             Exit For
    70.         End If
    71.     Next
    72.    
    73. End Function

    Oh well, wasted a few hours :S

    Thanks again.

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