gzj_06 发表于 2007-8-6 11:52:05

请教各位,我用下面的代码(参考1楼生成txt文件),在生成的log文件中怎么会有乱码,弄了半天也不知究竟是怎么回事
出现乱码主要是在追加文件的时候发生的,哪位帮帮忙,可以直接把我的代码拷到QTP中,注意scripting这个单词中的i有没有错,有错改一下,然后直接运行即可,在此先谢谢了!Option Explicit
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fileSystemObj, fileSpec
Dim currentTime, currentDate, logName, logFile, message
currentDate = Date
currentTime = Time
logName = "log"
Set fileSystemObj = CreateObject("scripting.FileSystemObject")
fileSpec ="D:\" &logName& ".txt" 'change this according to your directory
If not (fileSystemObj.FileExists(fileSpec)) Then
Set logFile = fileSystemObj.CreateTextFile(fileSpec, ForWriting, True)
logFile.WriteLine ("#######################################################################")
logFile.WriteLine (currentDate & currentTime & " Test: " & environment.Value("TestName") )
logFile.WriteLine ("#######################################################################")
logFile.Close
Set logFile = Nothing
End If
Set logFile = fileSystemObj.OpenTextFile(fileSpec, ForAppending, True)
message = "my message"
logFile.WriteLine ("##############################################")
logFile.WriteLine (message)
logFile.Close
Set logFile = Nothing
Set fileSystemObj = Nothing

gzj_06 发表于 2007-8-6 14:22:41

原因已经找到了,是Set logFile = fileSystemObj.CreateTextFile(fileSpec, ForWriting, True)里多了个ForWriting,去掉就对了

cxl216 发表于 2007-8-9 08:59:48

收藏一下。

auto_tester 发表于 2014-6-20 13:35:07

收藏~

mindy_1980 发表于 2014-7-15 16:20:47

回复来收藏
页: 1 [2]
查看完整版本: QTP日志实践的几点总结