例:ini文件内容如下,如何将key值对应的所有内容加到一个comboBox中。
[int]
等于 = =
大于 = >
小于 = <
[str]
等于 = =
大于 = >
小于 = <
包含              = like相当于
if Key值 = int
  comboBox.AddItem "等于"
  comboBox.AddItem "大于"
  comboBox.AddItem "小于"
if Key值 = str
  comboBox.AddItem "等于"
  comboBox.AddItem "大于"
  comboBox.AddItem "小于"
  comboBox.AddItem "包含"

解决方案 »

  1.   

    即: 已知key值= str
    如何根据该ini文件自动实现如下代码:  comboBox.AddItem "等于"
      comboBox.AddItem "大于"
      comboBox.AddItem "小于"
      comboBox.AddItem "包含"
      

  2.   

    楼猪啊,有问题多看看MSDN吧.
    GetPrivateProfileSection
    The GetPrivateProfileSection function retrieves all the keys and values for the specified section of an initialization file. Windows 95/98/Me: The specified profile section must not exceed 32K.Windows NT/2000 or later: The specified profile section has no size limit.Note  This function is provided only for compatibility with 16-bit applications written for Windows. Applications should store initialization information in the registry.DWORD GetPrivateProfileSection(
      LPCTSTR lpAppName,        // section name
      LPTSTR lpReturnedString,  // return buffer
      DWORD nSize,              // size of return buffer
      LPCTSTR lpFileName        // initialization file name
    );
    Parameters
    lpAppName 
    [in] Pointer to a null-terminated string specifying the name of the section in the initialization file. 
    lpReturnedString 
    [out] Pointer to a buffer that receives the key name and value pairs associated with the named section. The buffer is filled with one or more null-terminated strings; the last string is followed by a second null character. 
    nSize 
    [in] Specifies the size, in TCHARs, of the buffer pointed to by the lpReturnedString parameter. 
    Windows 95/98/Me: The maximum buffer size is 32,767 characters. lpFileName 
    [in] Pointer to a null-terminated string that specifies the name of the initialization file. If this parameter does not contain a full path to the file, the system searches for the file in the Windows directory. 
    Return Values
    The return value specifies the number of characters copied to the buffer, not including the terminating null character. If the buffer is not large enough to contain all the key name and value pairs associated with the named section, the return value is equal to nSize minus two. 
      

  3.   

    这个API函数GetPrivateProfileSection就是用来取出Section下面所有Key的,
    好好享用吧.
      

  4.   

    小吉的函数:Public 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
    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
    Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As Any, ByVal lpFileName As String) As Long
    Public Function GetIni(ByVal fileName As String, ByVal Section As String, ByVal Key As String, Optional BufLen As Long = 1024) As String
        Dim i As Long, s As String, j As Long
        s = Space(BufLen)
        i = GetPrivateProfileString(Section, Key, "", s, BufLen, fileName)
        If i > 0 Then
            s = Replace(RTrim(s), Chr(0) & Chr(0), "")
            If Right(s, 1) = Chr(0) Then
                GetIni = Left(s, Len(s) - 1)
            Else
                GetIni = s
            End If
        End If
    End Function
    '想读取一个节名下的所有配置项用这种方法:
    'Dim a() As String
    's = GetIni("配置名1", vbNullString, file)
    'a = Split(s, Chr(0))
    '所有配置项的Key就进入了数组a
      

  5.   

    sorry,多了两个API函数的声明
    WritePrivateProfileString
    WritePrivateProfileSection