先在工程菜单中引用一下Microsoft Scripting Runtime
然后在要写ini的事件中写代码,我以command1按钮(写)和command2按钮(读)的click事件为例:(具体项可以参看msdn)
Private Command1_Click() '写文件
dim fso as new filesystemobject
dim ts as textstream set ts=fso.opentextfile("ini文件存放路径+文件名.txt",ForWriting, True, TristateUseDefault)
ts.write(或writeline:按行写) 要写入文件的内容,字符串形式
end subPrivate Sub Command2_Click() ‘读文件
Dim fso As New FileSystemObject
Dim ts As TextStream
Set ts = fso.OpenTextFile("", ForReading, True, TristateUseDefault)
ts.ReadAll(这是读取所有文件内容。如果要按行读取,最好在写的时候每行前加行标,然后按行标进行读取,用ts.readline)
End Sub
然后在要写ini的事件中写代码,我以command1按钮(写)和command2按钮(读)的click事件为例:(具体项可以参看msdn)
Private Command1_Click() '写文件
dim fso as new filesystemobject
dim ts as textstream set ts=fso.opentextfile("ini文件存放路径+文件名.txt",ForWriting, True, TristateUseDefault)
ts.write(或writeline:按行写) 要写入文件的内容,字符串形式
end subPrivate Sub Command2_Click() ‘读文件
Dim fso As New FileSystemObject
Dim ts As TextStream
Set ts = fso.OpenTextFile("", ForReading, True, TristateUseDefault)
ts.ReadAll(这是读取所有文件内容。如果要按行读取,最好在写的时候每行前加行标,然后按行标进行读取,用ts.readline)
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货