资源描述:
《QTP日常详细函数库》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、'''以下为QuickTest和Robot都适用函数''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''获取当前日期PublicFunctionGet_Data() DimcurrentDate currentDate=Date Get_Data=currentDateEndFunction'获取当前时间PublicFunctionGet_Time() Dimcurre
2、ntTime currentTime=Time Get_Time=currentTimeEndFunction'随机函数生成'输入值:生成值范围i~j'返回值:随机数PublicFunctionGet_RandNum(fromNum,toNum) If(fromNum<0)Or(toNum<0)Then MsgBox"只接受大于零的输入" ElseIffromNum>toNumthen MsgBox"起始值必须小于结束值" Else DimRunTime Randomize RunTime=Int((10*Rnd)+1
3、) DimMyValue,i Fori=1ToRunTime Randomize MyValue=Int(((toNum-fromNum+1)*Rnd)+(fromNum)) Next Get_randNum=MyValue EndIfEndFunction'值交换函数PublicSubswap(byrefa,byrefb) Dimc c=a a=b b=cEndSub'是否是质数函数'是质数返回true,否则返回falseFunctionIsPrimeNumber(num) Dimi,flag flag=tr
4、ue Ifnum=1Then flag=False ElseIfnum<1Then MsgBox"只能接受大于0的数" flag=False Else Fori=2To(num-1) If((numModi)=0)Then flag=False ExitFor EndIf Next EndIf IsPrimeNumber=flagEndFunction'读指定文本文件指定行内容FunctionReadLine(pathway,rowcount) Dimfso,myfile,i,flag flag=1 Setfs
5、o=CreateObject("scripting.FileSystemObject") Iffso.FileExists(pathway)then Setmyfile=fso.openTextFile(pathway,1,false) Else flag=0 EndIf Fori=1torowcount-1 IfNotmyfile.AtEndOfLineThen myfile.SkipLine EndIf Next Ifflag=1then IfNotmyfile.AtEndOfLineThen ReadLine
6、=myfile.ReadLine Else ReadLine="文本越界" EndIf myfile.close Else ReadLine="文件不存在" EndIfEndFunction'随机生成字符串FunctionMakeString(inputlength) DimI,x,B,A IfIsNumeric(inputlength)Then ForI=1Toinputlength A=Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e",
7、"f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z") Randomize x=Get_RandNum(0,35) B=A(x) makestring=makestring+B Next MakeString=makestring else msgbox("只接受数字输入") EndIfEndFunction'启动资源管理器SubZYGLQ() DimWshShell setWshShell=CreateObj
8、ect("Wscript.Shell") WshShell.SendKeys"^+{ESC}" SetWshShell=nothingEndSub'启动运行SubRun() DimWshShell setWshShell=CreateObject("Wscript.Shell") WshShell.Se