VBS读写文件的代码一直无法搞定 吐槽
自学VBS无数回了前面的基本都能搞定 就是读写文件的代码写不出来 有阴影了 郁闷求教-ing 自学VBS无数回了前面的基本都能搞定 就是读写文件的代码写不出来 有阴影了 郁闷
求教-ing
379958495 发表于 2012-4-23 14:47 http://bbs.51testing.com/images/common/back.gif
你要读写的文件的格式是什么样子的呢?excel呢还是txt呢?
'//写文件
Public Function WriteTextFile(text,fpath)
Set fso = createobject("scripting.FileSystemObject")
If fso.FileExists(fpath) then
Set fopen = fso.OpenTextFile(fpath)
fopen.WriteLine(text)
fopen.Close
WriteTextFile = True
Else
WriteTextFile = False
End If
Set fso = Nothing
End Function
'//读文件
Public Function ReadTextFile(fpath)
i =0
Set fso = CreateObject("scripting.FileSystemObject")
If fso.FileExists(fpath) Then
Set fopen = fso.OpenTextFile(fpath)
While Not fopen.AtEndOfStream
ReDim Preserve tmpArry(i)
tmpArry(i) = fopen.ReadLine
i = i + 1
Wend
ReadTextFile = tmpArry '//返回数据
Else
ReadTextFile = False
End If
Set fso = Nothing
End Function
'//调用,并遍历数组
a = ReadTextFile("d:\test.txt")
For j = LBound(a) To UBound(a)
MsgBox a(j)
Next
:lol( ^_^ )不错嘛
页:
[1]