|
请教各位,我用下面的代码(参考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
复制代码 |
|