打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
QTP函数库

Archive for the ‘QTP函数库’ Category

MsgBoxTimeout - 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.  
  13. Function OpenFile(sFilename, iomode, create)
  14.   Set fso = CreateObject("Scripting.FileSystemObject")
  15.   Set OpenFile = fso.OpenTextFile(sFilename, iomode, create)
  16. End Function
  17.  
  18. ' 使用示例:
  19. WriteToFile "d:\beenhere.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.  
  13. Function OpenFile(sFilename, iomode, create)
  14.   Set fso = CreateObject("Scripting.FileSystemObject")
  15.   Set OpenFile = fso.OpenTextFile(sFilename, iomode, create)
  16. End Function
  17.  
  18. '使用示例 (与OpenFile函数配合使用)
  19. AppendToFile "d:\beenhere.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. '示例代码
  10. '打开d盘下的beenhere.txt文件,如果没有则自动创建该文件
  11. Set f = OpenFile("d:\beenhere.txt", 2, True)
  12. '将当前系统时间写入文件,如果文件之前已经有内容,则覆盖掉原有的内容
  13. f.WriteLine Now
  14. 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. ‘示例代码
  7.  Set f = CreateFile("c:\beenhere.txt", True) '在C盘创建一个名字为beenhere.txt的文件
  8.  f.WriteLine Now ’将当前系统时间写入文件
  9.  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.  
  10. msgbox NormalizeString ("http://www.threes.cn/blog/?p=799")
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
PHP正则替换函数preg
人民币大写转换自定义函数
从源代码中提取或过滤网页标签
实例讲解asp抓取网上房产信息
VBA: 判断动态数组是否为空
javascript中trim函数的实现
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服