VB读写INI文件实例!
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内容如下:
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
页:
[1]