QTP函數庫
06-07
Archive for the 『QTP函數庫』 CategoryMsgBoxTimeout - Message box彈出後可以自動關閉
Posted on the September 24th, 2009 under 其他 by threes
- Public Sub MsgBoxTimeout (Text, Title, TimeOut)
- Set WshShell = CreateObject("WScript.Shell")
- WshShell.Popup Text, TimeOut, Title
- End Sub
- "使用示例
- MsgBoxTimeout "abc","123",3
WriteToFile - 向文件中寫入內容,並且覆蓋原有的內容
Posted on the September 24th, 2009 under 文件操作 by threes
- "函數名:WriteToFile
- "作用:向文件中寫入內容,並且覆蓋原有的內容
- Function WriteToFile(sFilename, sLine)
- Const ForWriting = 2
- If sFilename = "" Then
- sFilename = Environment("SystemTempDir") & "QTDebug.txt"
- End If
- Set f = OpenFile(sFilename, ForWriting, True)
- f.WriteLine sLine
- f.Close
- End Function
- Function OpenFile(sFilename, iomode, create)
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set OpenFile = fso.OpenTextFile(sFilename, iomode, create)
- End Function
- " 使用示例:
- WriteToFile "d:eenhere.txt", Now
AppendToFile - 在文件中附加內容
Posted on the September 24th, 2009 under 文件操作 by threes
- "函數名:AppendToFile
- "作用:在文件中附加內容.
- Function AppendToFile(sFilename, sLine)
- Const ForAppending = 8
- If sFilename = "" Then
- sFilename = Environment("SystemTempDir")&"QTDebug.txt"
- End If
- Set f = OpenFile(sFilename, ForAppending, True)
- f.WriteLine sLine
- f.Close
- End Function
- Function OpenFile(sFilename, iomode, create)
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set OpenFile = fso.OpenTextFile(sFilename, iomode, create)
- End Function
- "使用示例 (與OpenFile函數配合使用)
- AppendToFile "d:eenhere.txt", Now
OpenFile - 打開指定的文件,返回一個可以用來讀、寫、附加內容到文件的TextStream對象
Posted on the September 24th, 2009 under 文件操作 by threes
- "函數名:OpenFile
- "作用:打開指定的文件,返回一個可以用來讀、寫、附加內容到文件的TextStream對象
- "參數iomode: 1-ForReading, 2-ForWriting, 8-ForAppending
- Function OpenFile(sFilename, iomode, create)
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set OpenFile = fso.OpenTextFile(sFilename,iomode,create)
- End Function
- "示例代碼
- "打開d盤下的beenhere.txt文件,如果沒有則自動創建該文件
- Set f = OpenFile("d:eenhere.txt", 2, True)
- "將當前系統時間寫入文件,如果文件之前已經有內容,則覆蓋掉原有的內容
- f.WriteLine Now
- f.Close
CreateFile - 創建一個可讀寫的文件
Posted on the September 24th, 2009 under 文件操作 by threes
- Function CreateFile(sFilename, bOverwrite)
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set CreateFile = fso.CreateTextFile(sFilename, bOverwrite)
- End Function
- 『示例代碼
- Set f = CreateFile("c:eenhere.txt", True) "在C盤創建一個名字為beenhere.txt的文件
- f.WriteLine Now 』將當前系統時間寫入文件
- f.Close
NormalizeString - 轉義QTP中的特殊字元,返回相應的正則表達式
Posted on the September 24th, 2009 under 字元操作 by threes
QTP中有幾個字元是需要被轉義之後才能正常使用(尤其是在對象識別中),而QTP自帶的幫助裡面提供了一個函數NormalizeString,可以實現這種轉義
- Function NormalizeString(OrgStr)
- Dim TempStr
- TempStr = Replace(OrgStr, "", "")
- TempStr = Replace(TempStr, "*", "*")
- TempStr = Replace(TempStr, "+", "+")
- TempStr = Replace(TempStr, ".", ".")
- NormalizeString = Replace(TempStr, "?", "?")
- End function
- msgbox NormalizeString ("http://www.threes.cn/blog/?p=799")
推薦閱讀:
※office excel最常用函數公式技巧搜集大全(13.12.09更新)17
※分段函數的複合函數要怎麼求(1)
※函數中傳入的參數是可變與不可變類型會怎樣?
※財務人員必懂得幾個Excel函數(三)
TAG:函數 |