Results 1 to 4 of 4

Thread: Get Keys List of a Section in inf file in vb6

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2012
    Posts
    106

    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,

  2. #2
    Addicted Member
    Join Date
    Sep 2008
    Posts
    141

    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2012
    Posts
    106

    Re: Get Keys List of a Section in inf file in vb6

    Greetings @brandoncampbell ,
    Thanks it works fine..

    regards,

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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 )

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