- UID
- 26372
注册时间2006-12-3
阅读权限30
最后登录1970-1-1
龙战于野
该用户从未签到
|
VB类程序读写 INI文件时,
声明API函数WritePrivateProfileString和GetPrivateProfileString
Private Sub shenzhuWriteIni(ByVal Filename As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
Dim buff As String * 128
buff = Value + Chr(0)
WritePrivateProfileString Section, Key, buff, Filename
End Sub
Private Function shenzhuReadIni(ByVal Filename As String,ByVal Section As String, ByVal Key As String) As String
Dim i As Long
Dim buff As String * 128
GetPrivateProfileString Section, Key, "", buff, 128, Filename
i = InStr(buff, Chr(0))
ReadFromIni = Trim(Left(buff, i - 1))
End Function
试例:
1、写INI文件
Dim Sz As Long
For Sz=1 To 4
Call shenzhuWriteIni(App.Path & "\key.ini", "Test", "Name" & Sz, "Value" & Sz) //调用
Next Sz
运行后key.ini内容如下:
[Test]
Name1=Value1
Name2=Value2
Name3=Value3
Name4=Value4
二、读INI文件
Dim Sz As Long
Dim Value(3) As String
For Sz=1 To 4
Value(Sz-1)=shenzhuReadIni(App.Path & "\key.ini", "Test", "Name" & Sz)
Next Sz |
|