例: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 "包含"
[int]
等于 = =
大于 = >
小于 = <
[str]
等于 = =
大于 = >
小于 = <
包含 = like相当于
if Key值 = int
comboBox.AddItem "等于"
comboBox.AddItem "大于"
comboBox.AddItem "小于"
if Key值 = str
comboBox.AddItem "等于"
comboBox.AddItem "大于"
comboBox.AddItem "小于"
comboBox.AddItem "包含"
如何根据该ini文件自动实现如下代码: comboBox.AddItem "等于"
comboBox.AddItem "大于"
comboBox.AddItem "小于"
comboBox.AddItem "包含"
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.
好好享用吧.
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
WritePrivateProfileString
WritePrivateProfileSection