发布新日志

  • 将我的电脑磁盘系统信息写入文本文件

    2007-08-20 22:03:28

    Dim a1,a2,a3,a4
    Set a1=createobject("scrīpting.filesystemobject")
    Set a2=a1.opentextfile("e:\info.txt",2,true)
    Set a3=a1.drives
    For each a4 in a3
            If a4.isready Then
                    a2.writeline a4.RootFolder.Type & a4.driveletter & "的文件系统是 '"&a4.filesystem&"'"
        else
                a2.writeline"the disk of " & a4.driveletter & " is not ready"
            End If
    Next
    a2.close

    运行后e:\info.txt文件内容如下:

    本地磁盘C的文件系统是 'NTFS'
    本地磁盘D的文件系统是 'NTFS'
    本地磁盘E的文件系统是 'FAT32'
    本地磁盘F的文件系统是 'NTFS'
    the disk of G is not ready
    the disk of H is not ready

  • 将字符串复制进剪贴板

    2007-08-19 21:19:33

    strCopy = "This text has been copied to the clipboard." 
    Set ōbjIE = CreateObject("InternetExplorer.Application") 
    objIE.Navigate("about:blank") 
    objIE.document.parentwindow.clipboardData.SetData "text", strCopy 
    objIE.Quit

    '再从剪贴板复制到编辑器

    Browser("网易电子邮箱 - 极速3.0Beta").Page("网易电子邮箱 - 极速3.0Beta").Frame("index").WebEdit("WebEdit_2").Object.focus
    wait 1
    Set wshShell = CreateObject("Wscrīpt.Shell")
    wshShell.SendKeys "{TAB}"
    wait 1
    wshShell.SendKeys "^v"
    wait 2

  • 修改完善的写log文件的QTP脚本

    2007-08-06 15:00:54

    参考自:http://bbs.51testing.com/thread-79991-1-1.html

    Public Sub WriteLogs(result)
     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("scrīpting.FileSystemObject")
     fileSpec ="D:\" &logName& ".txt" 'change this according to your directory
     If not (fileSystemObj.FileExists(fileSpec)) Then 
      Set logFile = fileSystemObj.CreateTextFile(fileSpec, 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, False)
     'result = "本测试用例通过!"
     logFile.WriteLine (currentDate & "  " & currentTime & "  " & result )
     logFile.Close
     Set logFile = Nothing
     Set fileSystemObj = Nothing
    End Sub

  • VBS脚本一行代码太长,使用换行符

    2007-08-03 17:55:05

    如果代码一行太长,想写成两行的话,要在行尾加下划线_)作续行符,例如:

    a = (1 + 2 + 3) * (1 + 2 + 3)
    
    '写成两行
    a = (1 + 2 + 3) * _
        (1 + 2 + 3)

    要想把多行代码写成一行,要用冒号:)作分隔符。例如:

    a = 1
    b = 2
    c = 3
    
    '写成一行
    a = 1 : b = 2 : c = 3

  • 读取文本文件的几个方法(ReadLine, SkipLine, ReadAll)

    2007-07-31 15:25:51

    ReadLine方法:读取文本文件的一行,每执行一次,文件读取指针自动移到下一行,再执行时,读取的就是下一行的内容,如:
    msg1=myfile.ReadLine         '读取第一行
    msg2=myfile.ReadLine           '读取第二行
    msg3=myfile.ReadLine           '读取第三行
    msgbox msg1
    msgbox msg2
    msgbox msg3
    SkipLine方法:跳过下一行,执行之后,文件读取指针移到下一行的下一行行首,如:
    msg1=myfile.ReadLine       '读取的是第一行
    myfile.SkipLine              '此句执行过后,指针已经移到了第三行行首

    msg2=myfile.ReadLine         '读取的是第三行
    msgbox msg1
    msgbox msg2
    ReadAll方法就是读取整个文件的内容,如:
    Dim fso, myfile,msg, tmp, i
    Set fso=CreateObject("scrīpting.FileSystemObject")   
    Set myfile = fso.openTextFile("C:\login.txt",1,false)
    'msg1=myfile.ReadLine
    'msg2=myfile.ReadLine
    'msg3=myfile.ReadLine
    msg = myfile.ReadAll
    tmp = split(msg, vbcrlf)    '将各行的内容存放到tmp数组中
    For i=0 to Ubound(tmp)
      msgbox tmp(i)
    Next
    myfile.close

Open Toolbar