模块代码
以下是模块片段: 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 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 |
窗体引用
以下是读取代码片段: Dim ret As Long Dim buff As String buff = String(255, 0) ret = GetPrivateProfileString("Myapp", "text1", "text1", buff, 256, "c:aa.ini") ’若.ini MyApp中无text1,则采用叁数三的值 Text1.Text = buff buff = String(255, 0) ret = GetPrivateProfileString("Myapp", "text2", "text2", buff, 256, "c:aa.ini") Text2.Text = buff buff = String(255, 0) ret = GetPrivateProfileString("Myapp2", "text3", "text3", buff, 256, "c:aa.ini") Text3.Text = buff |
以下是写入片段: Dim success As Long success = WritePrivateProfileString("MyApp", "text1", Text1.Text, "c:aa.ini") ’叁数一 Section Name ’叁数二 於.ini中的项目 ’叁数三 项目的内容 ’叁数四 .ini文件的名称 success = WritePrivateProfileString("MyApp", "text2", Text2.Text, "c:aa.ini") success = WritePrivateProfileString("MyApp2", "text3", Text3.Text, "c:aa.ini") |
说明:读取和写入为模块中定义的两个api函数 WritePrivateProfileString()和WritePrivateProfileString(),这两个函数有4个参数 参数1为section, 参数2为keyword,参数2为keyword,参数2为value,参数4为filename,具体见下:
c:text.ini-------------filename
[section1]
keyword1=valuel
keyword2=value2
……
[section2]
keyword1=value1
keyword2=value2
……