標籤:

QTP函數庫

Archive for the 『QTP函數庫』 CategoryMsgBoxTimeout - Message box彈出後可以自動關閉

Posted on the September 24th, 2009 under 其他 by threes

  1. Public Sub MsgBoxTimeout (Text, Title, TimeOut)
  2. Set WshShell = CreateObject("WScript.Shell")
  3. WshShell.Popup Text, TimeOut, Title
  4. End Sub
  5. "使用示例
  6. MsgBoxTimeout "abc","123",3

WriteToFile - 向文件中寫入內容,並且覆蓋原有的內容

Posted on the September 24th, 2009 under 文件操作 by threes

  1. "函數名:WriteToFile
  2. "作用:向文件中寫入內容,並且覆蓋原有的內容
  3. Function WriteToFile(sFilename, sLine)
  4. Const ForWriting = 2
  5. If sFilename = "" Then
  6. sFilename = Environment("SystemTempDir") & "QTDebug.txt"
  7. End If
  8. Set f = OpenFile(sFilename, ForWriting, True)
  9. f.WriteLine sLine
  10. f.Close
  11. End Function
  12. Function OpenFile(sFilename, iomode, create)
  13. Set fso = CreateObject("Scripting.FileSystemObject")
  14. Set OpenFile = fso.OpenTextFile(sFilename, iomode, create)
  15. End Function
  16. " 使用示例:
  17. WriteToFile "d:eenhere.txt", Now

AppendToFile - 在文件中附加內容

Posted on the September 24th, 2009 under 文件操作 by threes

  1. "函數名:AppendToFile
  2. "作用:在文件中附加內容.
  3. Function AppendToFile(sFilename, sLine)
  4. Const ForAppending = 8
  5. If sFilename = "" Then
  6. sFilename = Environment("SystemTempDir")&"QTDebug.txt"
  7. End If
  8. Set f = OpenFile(sFilename, ForAppending, True)
  9. f.WriteLine sLine
  10. f.Close
  11. End Function
  12. Function OpenFile(sFilename, iomode, create)
  13. Set fso = CreateObject("Scripting.FileSystemObject")
  14. Set OpenFile = fso.OpenTextFile(sFilename, iomode, create)
  15. End Function
  16. "使用示例 (與OpenFile函數配合使用)
  17. AppendToFile "d:eenhere.txt", Now

OpenFile - 打開指定的文件,返回一個可以用來讀、寫、附加內容到文件的TextStream對象

Posted on the September 24th, 2009 under 文件操作 by threes

  1. "函數名:OpenFile
  2. "作用:打開指定的文件,返回一個可以用來讀、寫、附加內容到文件的TextStream對象
  3. "參數iomode: 1-ForReading, 2-ForWriting, 8-ForAppending
  4. Function OpenFile(sFilename, iomode, create)
  5. Set fso = CreateObject("Scripting.FileSystemObject")
  6. Set OpenFile = fso.OpenTextFile(sFilename,iomode,create)
  7. End Function
  8. "示例代碼
  9. "打開d盤下的beenhere.txt文件,如果沒有則自動創建該文件
  10. Set f = OpenFile("d:eenhere.txt", 2, True)
  11. "將當前系統時間寫入文件,如果文件之前已經有內容,則覆蓋掉原有的內容
  12. f.WriteLine Now
  13. f.Close

CreateFile - 創建一個可讀寫的文件

Posted on the September 24th, 2009 under 文件操作 by threes

  1. Function CreateFile(sFilename, bOverwrite)
  2. Set fso = CreateObject("Scripting.FileSystemObject")
  3. Set CreateFile = fso.CreateTextFile(sFilename, bOverwrite)
  4. End Function
  5. 『示例代碼
  6. Set f = CreateFile("c:eenhere.txt", True) "在C盤創建一個名字為beenhere.txt的文件
  7. f.WriteLine Now 』將當前系統時間寫入文件
  8. f.Close

NormalizeString - 轉義QTP中的特殊字元,返回相應的正則表達式

Posted on the September 24th, 2009 under 字元操作 by threes

QTP中有幾個字元是需要被轉義之後才能正常使用(尤其是在對象識別中),而QTP自帶的幫助裡面提供了一個函數NormalizeString,可以實現這種轉義

  1. Function NormalizeString(OrgStr)
  2. Dim TempStr
  3. TempStr = Replace(OrgStr, "", "")
  4. TempStr = Replace(TempStr, "*", "*")
  5. TempStr = Replace(TempStr, "+", "+")
  6. TempStr = Replace(TempStr, ".", ".")
  7. NormalizeString = Replace(TempStr, "?", "?")
  8. End function
  9. msgbox NormalizeString ("http://www.threes.cn/blog/?p=799")

推薦閱讀:

office excel最常用函數公式技巧搜集大全(13.12.09更新)17
分段函數的複合函數要怎麼求(1)
函數中傳入的參數是可變與不可變類型會怎樣?
財務人員必懂得幾個Excel函數(三)

TAG:函數 |