出现乱码主要是在追加文件的时候发生的,哪位帮帮忙,可以直接把我的代码拷到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 原因已经找到了,是Set logFile = fileSystemObj.CreateTextFile(fileSpec, ForWriting, True)里多了个ForWriting,去掉就对了 收藏一下。 收藏~ 回复来收藏
页:
1
[2]