Access/VBA Library

INI_GetSection

Returns Dictionary containing all keys in the specified section and their values.

Syntax

INI_GetSection( section )
Parameters
Name Type Description
section String Required. Name of the section to be read.
Return value

Dictionary : The keys correspond to the keys within the section.

Code
Public Function INI_GetSection(ByVal section As String) As Dictionary
    Dim buffer As String
    Dim length As Long
    Dim arrKeys
    Dim result As New Dictionary
    Dim i As Long
    ' Create buffer (large)
    buffer = Space$(MAX_BUF_SIZE * 10)
    ' Get list of all keys within section (key = vbNullChar)
    length = GetPrivateProfileString( _
                section, _
                vbNullString, _
                "", _
                buffer, _
                Len(buffer), _
                INI_Filename())
    ' The keys are separated by Null-values
    arrKeys = Split(Left$(buffer, length), vbNullChar)
    ' Last item is also followed by a Null-value
    For i = LBound(arrKeys) To UBound(arrKeys) - 1
        ' Retrieve key value and store it in a Dictionary
        result.Add arrKeys(i), INI_GetValue(section & "." & arrKeys(i))
    Next i
    
    Set INI_GetSection = result

End Function
Dictionarytag:Dictionary

See also

  • GetPrivateProfileString
  • INI_GetValue
Example
Dim dict As Dictionary
Dim key
Set dict = INI_GetSection("config")
For Each k In dict.Keys
    Debug.Print key, dict(key)
Next k