Results 1 to 3 of 3

Thread: VB6 - READING & WRITING TO .INI

  1. #1
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 06
    Location
    Australia, Melbourne
    Posts
    2,306

    VB6 - READING & WRITING TO .INI

    VB Code:
    1. Private Declare Function GetPrivateProfileString Lib "KERNEL32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
    2. Private Declare Function WritePrivateProfileString Lib "KERNEL32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
    3. Public Sub WriteINI(wiSection As String, wiKey As String, wiValue As String, wiFile As String)
    4.     WritePrivateProfileString wiSection, wiKey, wiValue, App.Path & "\" & wiFile
    5. End Sub
    6. Public Function ReadINI(riSection As String, riKey As String, riFile As String, riDefault As String)
    7.     Dim sRiBuffer As String
    8.     Dim sRiValue As String
    9.     Dim sRiLong As String
    10.     Dim INIFile As String
    11.     INIFile = App.Path & "\" & riFile
    12.     If Dir(INIFile) <> "" Then
    13.         sRiBuffer = String(255, vbNull)
    14.         sRiLong = GetPrivateProfileString(riSection, riKey, Chr(1), sRiBuffer, 255, INIFile)
    15.         If Left$(sRiBuffer, 1) <> Chr(1) Then
    16.             sRiValue = Left$(sRiBuffer, sRiLong)
    17.             If sRiValue <> "" Then
    18.                 ReadINI = sRiValue
    19.             Else
    20.                 ReadINI = riDefault
    21.             End If
    22.         Else
    23.             ReadINI = riDefault
    24.         End If
    25.     Else
    26.         ReadINI = riDefault
    27.     End If
    28. End Function

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 04
    Location
    on the poop deck
    Posts
    5,587

    Re: VB6 - READING & WRITING TO .INI

    there are already plenty of other (and better) INI handling examples in this forum (1, 2, 3, 4, 5, 6) - i suggest you search next time before posting, as per the codebank guidelines

  3. #3
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 06
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: VB6 - READING & WRITING TO .INI

    Lol i posted this because i made it and i don't like copy and pasting **** from others. But thanks for the tip.

Posting Permissions

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