-
I have an ini file that I need to read and write to
It looks like this
[Friends]
Jonnie:34.131.256.204
Bill:262.159.45.224
Does anyone have a routine or a bas module that will let me get the entries under [FRIENDS] and get the total count
of the entries under the heading ?
Thanx guys
-
Here you go:
Code:
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Function readini(strsection As String, strkey As String, strfullpath As String) As String
Dim strbuffer As String
Let strbuffer$ = String$(750, Chr$(0&))
Let readini$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
End Function
Usage:
Text1.text = readini("Friends", "Jonnie", "C:\Friends.ini")
-
Thanx =)
How bout this now
what happens If I Dont know the entries under [Friends]
How can I Find out how many entries there are ?
Also how bout a writeini function ?
-
Here is how to Write an INI:
Code:
Public 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
Public Sub writeini(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String)
Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$)
End Sub
Call writeini("Friends.ini", "NewFriend", "Number", "C:\Friends.ini")
Don't know how to find all entries under [Friends], but you can open and through VB and look through it.
Code:
Open "C:\Friends.ini" For Input As #1
Text1.Text = Input$(LOF(1), 1)
Close #1
-
Thanx again Mathew , I appreciate your help