VB之fso-file

Sub writelog(filepath,logstr)

Const ForReading=1,ForWritting=2,ForAppdening=8

'创建文件

Dim fso,f

Dim teststr

Set fso=CreateObject("scripting.filesystemobject")

If fso.FileExists("D:test.txt") Then

MsgBox "Exist"

Else

MsgBox "Not Exist"

Set f=fso.CreateTextFile(filepath)

End If

 

 

'将数据写进文本中

Set f=fso.OpenTextFile(filepath,ForAppdening,false)

f.WriteLine logstr

f.Close

 

 

'将文本的数据读出来

Set f=fso.OpenTextFile(filepath,ForReading,False)

teststr=f.ReadLine

MsgBox teststr

f.Close

Set fso=Nothing

End Sub

 

writelog "D:\test.txt",Now()&"----执行自动化测试"

 

posted @ 2018-06-07 15:39  旧时光里的小鱼儿  阅读(321)  评论(0编辑  收藏  举报