Get Keys List of a Section in inf file in vb6
Hello,
I am using the following code to read/write information of a INF file.
Code:
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationname As String, ByVal lpKeyName As Any, ByVal lsString As Any, ByVal lplFilename As String) As Long
Private 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 RD(Section As String, Key As String, strFileName As String) As String
On Error Resume Next
Dim lngResult As Long
Dim strResult As String * 255
lngResult = GetPrivateProfileString(Section, Key, strFileName, strResult, Len(strResult), strFileName)
RD = Trim$(strResult)
End Function
Public Function WD(Section As String, Key As String, Content As String, strFileName As String)
On Error Resume Next
Dim lngResult As Long
lngResult = WritePrivateProfileString(Section, Key, Content, strFileName)
End Function
Now, I need to Read all the Keys of a specific Section in the INF file..
For Example:
The INF data is something like:
[config]
DATA1=abcd
DATA2=efgh
DATA3=1234
I want to Read How many Keys (DATA1,DATA2...so on) are Present under "config" Section and want to load these keys data in a listbox..
Please help me to solveout this..
Thanks
Regards,
Re: Get Keys List of a Section in inf file in vb6
Been a while since I looked at ini files.. but I think you want to go with
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
something like you already have
Public Function RS(Filename As String, Section As String) As String
Dim lngResult As Long
Dim strResult As String * 255
lngResult = GetPrivateProfileSection(Section, strResult, Len(strResult), Filename)
RS = Trim$(strResult)
End Function
debug.print rs(c:\filelocation\filename.ini, "config")
you might want to split the information and add to list, but this is how to return a section.
Re: Get Keys List of a Section in inf file in vb6
Greetings @brandoncampbell ,
Thanks it works fine.. :)
regards,
Re: Get Keys List of a Section in inf file in vb6
Moved From The CodeBank (which is for sharing code rather than posting questions :) )