Download
  VBScript New code


  1. '查询Access数据库字符出现次数

  2. Function Access_GetCount(DBlocation,TableName,Value)
  3.    set con=createobject("adodb.connection")
  4.    con.open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & DBlocation
  5.    set record = createobject("adodb.recordset")
  6.    sql="select * from " & TableName
  7.    record.open sql,con
  8.    DO
  9.        if(record("name")=Value)then
  10.           num=num+1
  11.        end If
  12.      record.MoveNext
  13.      loop until record.eof=True
  14.      record.close
  15.      set record=Nothing
  16.      con.close
  17.      set con=Nothing
  18.      If num = 0 Then
  19.         Access_GetCount = 0
  20.      Else
  21.         Access_GetCount = num
  22.      End If
  23. End Function



  24. '按ASCII码值冒泡排序
  25. '参数说明:待排序的字符串 分隔符 排序方式:
  26. '1降序,2升序 排序完的序列
  27. Function BubbleSort(VString,Spl,Func)
  28.     Dim Str,StrLength,i,j
  29.     Str = Split(VString,Spl)
  30.     StrLength = UBound(Str) + 1
  31.     For i = 1 To (StrLength-1)
  32.         For j = (i+1) To StrLength
  33.             If Func = 1 then
  34.                 If Asc(Str(i-1)) < Asc(Str(j-1)) Then
  35.                     Call Swap(Str(i-1),Str(j-1))
  36.                 End If
  37.             Else
  38.                 If Asc(Str(i-1)) > Asc(Str(j-1)) Then
  39.                     Call Swap(Str(i-1),Str(j-1))
  40.                 End If
  41.             End If
  42.         Next
  43.     Next
  44.     j = ""
  45.     For i = 1 To StrLength
  46.         j = j & Str(i-1) & Spl
  47.     Next
  48.     j = Left(j,(StrLength * 2 -1))
  49.     BubbleSort = j
  50. End Function



  51. '检查是否存在数字 输入字符串 true:存在数字 false:不存在数字

  52. Function checkString (myString)
  53.     checkString = False
  54.     Dim myChr
  55.     For myChr = 48 to 57
  56.         If InStr(myString,Chr(myChr)) > 0 Then
  57.             checkString = True
  58.             Exit Function
  59.         End If
  60.     Next
  61. End Function



  62. '计算两个日期之间相隔几天
  63. Function Days(ByVal SourceData, ByVal DesData)
  64.     Dim flag, temp1, temp2, OPYear1, OPYear2, OPMonth1, OPMonth2, OPDay1, OPDay2, i, tempDay
  65.     temp1 = Split(SourceData, "-")
  66.     temp2 = Split(DesData, "-")
  67.     If ((UBound(temp1) + 1) <> 3) Or ((UBound(temp2) + 1) <> 3) Then
  68.         MsgBox "输入参数不对劲", , "Days函数提示"
  69.     End If
  70.     OPYear1 = temp1(0)
  71.     OPMonth1 = temp1(1)
  72.     OPDay1 = temp1(2)
  73.     OPYear2 = temp2(0)
  74.     OPMonth2 = temp2(1)
  75.     OPDay2 = temp2(2)
  76.     If CInt(OPYear1) <> CInt(OPYear2) Then
  77.         If CInt(OPYear1) > CInt(OPYear2) Then
  78.             flag = "big"
  79.         ElseIf CInt(OPYear1) < CInt(OPYear2) Then
  80.             flag = "small"
  81.         End If
  82.     Else
  83.         If CInt(OPMonth1) <> CInt(OPMonth2) Then
  84.             If CInt(OPMonth1) > CInt(OPMonth2) Then
  85.                 flag = "big"
  86.             ElseIf CInt(OPMonth1) < CInt(OPMonth2) Then
  87.                 flag = "small"
  88.             End If
  89.         Else
  90.             If CInt(OPDay1) <> CInt(OPDay2) Then
  91.                 If CInt(OPDay1) > CInt(OPDay2) Then
  92.                     flag = "big"
  93.                 ElseIf CInt(OPDay1) < CInt(OPDay2) Then
  94.                     flag = "small"
  95.                 End If
  96.             Else
  97.                 flag = "="
  98.             End If
  99.         End If
  100.     End If

  101.     If (flag = "big") Then
  102.         i = 1
  103.         tempDay = DesData
  104.         Do
  105.             tempDay = Nextday(tempDay)
  106.             i = i + 1
  107.         Loop Until tempDay = SourceData
  108.         i = i - 1
  109.     ElseIf (flag = "small") Then
  110.         i = 1
  111.         tempDay = SourceData
  112.         Do
  113.             tempDay = Nextday(tempDay)
  114.             i = i + 1
  115.         Loop Until tempDay = DesData
  116.         i = i - 1
  117.     Else
  118.         i = 0
  119.     End If

  120.     Days = i
  121. End Function



  122. '删除指定的目录
  123. '调用示例:DeleteAFolder("c:\log")
  124. Sub DeleteAFolder(filespec)
  125. On Error Resume Next
  126.    Dim fso
  127.    Set fso = CreateObject("Scripting.FileSystemObject")
  128.    fso.DeleteFolder(filespec)
  129.    Set fso=Nothing
  130. End Sub


  131. '日志输出函数,包含三个参数
  132. '参数1:tcfile,执行用例文件名称
  133. '参数2:报告输出存放路径
  134. '调用示例:call ExecuteTc("d:\share\Config.txt","c:\log")

  135. Function ExecuteTc(tcfile,reportpath)
  136. On Error Resume Next
  137.    Dim arrpaths,arrtcs,dicConfig

  138. '初始化
  139.    Set dicConfig=CreateObject("Scripting.Dictionary")
  140.    Set fso=CreateObject("Scripting.FileSystemObject")
  141.    If fso.FileExists(tcfile) Then
  142.    Else
  143.      Exit Function
  144.    End If
  145. '删除结果目录内容
  146.    fso.DeleteFolder(reportpath)
  147.    
  148. '读取配置文件内容,并将这些内容放到Dictionary中
  149.    Set f=fso.OpenTextFile(tcfile)
  150.    Do While(f.AtEndOfStream=false)
  151.       strline=f.ReadLine
  152.         If(Instr(strline,"=")> 1 ) Then
  153.          arr=Split(strline,"=")
  154.          configItem=LTrim(arr(0))
  155.          configItem=RTrim(configItem)
  156.          configValue=LTrim(arr(1))
  157.          configValue=RTrim(configValue)
  158.          dicConfig.Add configItem,configValue
  159.         End If
  160.    Loop
  161. '将Dictionary中值和键分别放到数组中
  162.    arrpaths=dicConfig.items
  163.    arrtcs=dicConfig.keys
  164.    
  165. '循环读取用例,执行并将结果存放于指定目录
  166.    For i = 0 To dicConfig.Count -1
  167.      Dim qtApp
  168. '杀进程
  169.         KillProc("IEXPLORE.EXE")
  170.           KillProc("QTPro.exe")
  171.           KillProc("QTAutomationAgent.exe")    
  172.      Set qtApp = CreateObject("QuickTest.Application")
  173.      qtApp.Launch
  174.      qtApp.Visible =True
  175.      qtApp.Open arrpaths(i),True
  176.      Set qtTest=qtApp.test
  177.      Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")
  178.      qtResultsOpt.ResultsLocation = reportpath & "\"&arrtcs(i)
  179.      qtTest.run qtResultsOpt
  180.      qtApp.quit
  181.      Set qtApp=Nothing
  182. '杀进程
  183.         KillProc("IEXPLORE.EXE")
  184.           KillProc("QTPro.exe")
  185.           KillProc("QTAutomationAgent.exe")         
  186.    Next

  187. '释放资源
  188.    Set dicConfig=Nothing
  189.    Set fso=Nothing
  190.    Set f=Nothing
  191.    Set arrpaths= Nothing
  192.    Set arrtcs=Nothing
  193.    Set configvalue=Nothing
  194.    Set configitem=Nothing
  195.    Set arr=Nothing
  196.    Set strline=Nothing

  197. End Function


  198. '获取当前日期
  199. Public Function Get_Data()
  200.     Dim currentDate
  201.     currentDate = Date
  202.     Get_Data = currentDate
  203. End Function

  204. '获取当前时间
  205. Public Function Get_Time()
  206.     Dim currentTime
  207.     currentTime = Time
  208.     Get_Time = currentTime
  209. End Function

  210. '随机函数生成
  211. '输入值:生成值范围 i~j
  212. '返回值:随机数
  213. Public Function Get_RandNum(fromNum,toNum)
  214.     If (fromNum<0) Or (toNum<0) Then
  215.         MsgBox "只接受大于零的输入"
  216.     ElseIf fromNum>toNum then
  217.         MsgBox "起始值必须小于结束值"
  218.     Else
  219.         Dim RunTime
  220.         Randomize
  221.         RunTime = Int((10 * Rnd) + 1)
  222.         Dim MyValue,i
  223.         For i = 1 To RunTime
  224.             Randomize
  225.             MyValue = Int(((toNum - fromNum + 1) * Rnd) + (fromNum))
  226.         Next
  227.      Get_randNum=MyValue
  228.      End If
  229. End Function

  230. '求字符串长度(中文算2个西文字符)
  231. Function GetLen(Str)
  232.         Dim singleStr, i, iCount
  233.         iCount = 0
  234.         For i = 1 to len(Str)
  235.                 singleStr = mid(Str,i,1)
  236.                 If asc(singleStr) < 0 Then
  237.                         iCount = iCount + 2
  238.                 Else
  239.                         iCount = iCount + 1
  240.                 End If
  241.         Next
  242.         GetLen = iCount
  243. End Function




  244. Sub HighlightAll(TestObject)

  245.        Dim Parent, Desc, Props, PropsCount, MaxIndex, i, Objs
  246.        If IsEmpty(TestObject.GetTOProperty("parent")) Then
  247.               Set Parent = Desktop
  248.        Else
  249.               Set Parent = TestObject.GetTOProperty("parent")
  250.        End If
  251.        Set Desc = Description.Create
  252.        Set Props = TestObject.GetTOProperties
  253.        PropsCount = Props.Count - 1
  254.        For i = 0 to PropsCount
  255.               Desc(Props(i).Name).Value = Props(i).Value
  256.        Next
  257.        Set Objs = Parent.ChildObjects(Desc)
  258.        MaxIndex= Objs.Count - 1
  259.        For i = 0 to MaxIndex
  260.               Objs.Item(i).Highlight
  261.        Next

  262. End Sub



  263. '是否是质数函数
  264. '是质数返回true,否则返回False
  265. Function IsPrimeNumber(num)
  266.     Dim i,flag
  267.     flag = true
  268.     If num = 1 Then
  269.         flag = False
  270.     ElseIf num < 1 Then
  271.         MsgBox "只能接受大于0的数"
  272.         flag = False
  273.     Else
  274.         For i = 2 To (num - 1)
  275.             If ((num Mod i) = 0) Then
  276.                 flag = False
  277.                 Exit For
  278.             End If
  279.         Next
  280.     End If    
  281.     IsPrimeNumber = flag
  282. End Function

  283. '是否闰年
  284. Function ISLeapYear(ByVal inYear)
  285.     If ((inYear Mod 4 = 0 And inYear Mod 100 <> 0) Or inYear Mod 400 = 0) Then
  286.         ISLeapYear = True
  287.     Else
  288.         ISLeapYear = False
  289.     End If
  290. End Function

  291. '检查身份证号是否正确
  292. Function Identification(Text1)
  293. xian = Text1
  294. If (Not IsNumeric(Left(Text1, 15)) And Not IsNumeric(Left(Text1, 18))) Or Text1 = "" Then
  295.   Identification = False
  296.   Exit Function
  297. End If
  298. lenx = Len(Trim(Text1))
  299. If lenx = 15 Or lenx = 18 Then
  300.     If lenx = 15 Then
  301.         yy = "19" & Mid(xian, 7, 2)
  302.         mm = Mid(xian, 9, 2)
  303.         dd = Mid(xian, 11, 2)
  304.         aa = Right(xian, 1)
  305.     End If
  306.     If lenx = 18 Then
  307.         yy = Mid(xian, 7, 4)
  308.         mm = Mid(xian, 11, 2)
  309.         dd = Mid(xian, 13, 2)
  310.         aa = Right(xian, 1)
  311.     End If
  312.     If CInt(mm) > 12 Or CInt(dd) > 31 Then
  313.        Identification = False
  314.        Exit Function
  315.     Else
  316.         Identification = True
  317.         Exit Function
  318.     End If
  319. Else
  320.   Identification = False
  321.   Exit Function
  322. End If
  323. End Function



  324. '杀死指定名称的进程
  325. '调用示例:KillProc("Foxmail.exe")

  326. Function KillProc(strProcName)
  327.     Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
  328.     Set arrProcesses = objWMIService.ExecQuery( "select * from win32_process where Name ='"&strProcName&"'" )
  329.     For Each proccess In arrProcesses
  330.         proccess.Terminate 0
  331.     Next
  332. End Function


  333. '随机生成字符串
  334. '调用示例:str=MakeString(10)

  335. Function MakeString(inputlength)
  336.     Dim I,x,B,A
  337.     If IsNumeric(inputlength) Then
  338.     For I = 1 To inputlength
  339.         A = Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
  340.         Randomize
  341.         x=Get_RandNum(0,35)
  342.         B = A(x)
  343.         makestring =makestring +B
  344.     Next
  345.         MakeString = makestring
  346.     else
  347.         msgbox ("只接受数字输入")
  348.     End If
  349. End Function



  350. '去掉字符串中的重复项
  351. Function NoRepeat(Inp,Sp)
  352. Dim aa,flag,words,length,i,j,k,sp1,sp2,cc
  353.     aa = Inp
  354.     Do
  355.         flag = False
  356.         words = Split(aa,Sp)
  357.         length = UBound(words)
  358.         For i = 0 To (length -1)
  359.             sp1 = words(i)
  360.             For j = (i+1) To length
  361.                 sp2 = words(j)
  362.                 If sp1 = sp2 Then
  363.                     flag = True
  364.                     aa = ""
  365.                     For k = 0 To (j-1)
  366.                         aa = aa & words(k) & sp
  367.                     Next
  368.                     For k = (j + 1) To length
  369.                         aa = aa & words(k) & sp
  370.                     Next
  371.                     
  372.                     cc = Len(aa)
  373.                     aa = Left(aa,(cc - 1))
  374.                 End If
  375.             Next
  376.             If flag = True Then
  377.                 Exit For
  378.             End if
  379.         Next
  380.     Loop Until flag = false
  381.     NoRepeat = aa
  382. End Function

  383. '求下一天是几号的函数
  384. Function Nextday(ByVal inputday)
  385.     Dim temp, num, OPYear, OPMonth, OPDay, ret, flag
  386.     temp = Split(CStr(inputday), "-")
  387.     num = UBound(temp) + 1
  388.     OPYear = temp(0)
  389.     OPMonth = temp(1)
  390.     OPDay = temp(2)
  391.     flag = 0

  392.     If OPMonth = 1 Or OPMonth = 3 Or OPMonth = 5 Or OPMonth = 7 Or OPMonth = 8 Or OPMonth = 10 Or OPMonth = 12 Then
  393.         If OPDay > 31 Or OPDay < 1 Then
  394.             flag = 1
  395.         End If
  396.     ElseIf OPMonth = 4 Or OPMonth = 6 Or OPMonth = 9 Or OPMonth = 11 Then
  397.         If OPDay > 30 Or OPDay < 1 Then
  398.             flag = 1
  399.         End If
  400.     Else
  401.         If ISLeapYear(OPYear) Then
  402.             If OPDay > 29 Or OPDay < 1 Then
  403.                 flag = 1
  404.             End If
  405.         Else
  406.             If OPDay > 28 Or OPDay < 1 Then
  407.                 flag = 1
  408.             End If
  409.         End If
  410.     End If

  411.     If flag = 1 Or num <> 3 Then
  412.         MsgBox "输入参数不对劲", , "Nextday函数提示"
  413.     Else
  414.         If OPMonth = 1 Or OPMonth = 3 Or OPMonth = 5 Or OPMonth = 7 Or OPMonth = 8 Or OPMonth = 10 Or OPMonth = 12 Then 'big month
  415.             If OPDay = 31 Then
  416.                 OPDay = 1
  417.                 If OPMonth = 12 Then
  418.                     OPMonth = 1
  419.                     OPYear = OPYear + 1
  420.                 Else
  421.                     OPMonth = OPMonth + 1
  422.                     OPYear = OPYear
  423.                 End If
  424.             Else
  425.                 OPDay = OPDay + 1
  426.             End If
  427.         ElseIf OPMonth = 4 Or OPMonth = 6 Or OPMonth = 9 Or OPMonth = 11 Then 'small month
  428.             If OPDay = 30 Then
  429.                 OPDay = 1
  430.                 If OPMonth = 12 Then
  431.                     OPMonth = 1
  432.                     OPYear = OPYear + 1
  433.                 Else
  434.                     OPMonth = OPMonth + 1
  435.                     OPYear = OPYear
  436.                 End If
  437.             Else
  438.                 OPDay = OPDay + 1
  439.             End If
  440.         Else 'February
  441.             If ISLeapYear(OPYear) Then
  442.                 If OPDay = 29 Then
  443.                     OPDay = 1
  444.                     If OPMonth = 12 Then
  445.                         OPMonth = 1
  446.                         OPYear = OPYear + 1
  447.                     Else
  448.                         OPMonth = OPMonth + 1
  449.                         OPYear = OPYear
  450.                     End If
  451.                 Else
  452.                     OPDay = OPDay + 1
  453.                 End If
  454.             Else
  455.                 If OPDay = 28 Then
  456.                     OPDay = 1
  457.                     If OPMonth = 12 Then
  458.                         OPMonth = 1
  459.                         OPYear = OPYear + 1
  460.                     Else
  461.                         OPMonth = OPMonth + 1
  462.                         OPYear = OPYear
  463.                     End If
  464.                 Else
  465.                     OPDay = OPDay + 1
  466.                 End If
  467.             End If
  468.         End If
  469.         ret = OPYear & "-" & OPMonth & "-" & OPDay
  470.         Nextday = ret
  471.     End If
  472. End Function



  473. Public Function OpenIE( byval dAddress)
  474.    SystemUtil.Run "iexplore.exe", dAddress
  475. End Function


  476. '让QTP运行时保持最小化
  477. Public Sub QTP_Small()
  478.     Dim objQTPWin
  479.     Set objQTPWin = GetObject("" , "QuickTest.Application")
  480.     objQTPWin.WindowState = "Minimized"
  481.     Set objQTPWin = Nothing
  482. End Sub

  483. '恢复QTP窗口
  484. Public Sub QTP_Big()
  485.     Dim objQTPWin
  486.     Set objQTPWin = GetObject("" , "QuickTest.Application")
  487.     objQTPWin.WindowState = "Restored"
  488.     Set objQTPWin = Nothing
  489. End Sub



  490. '写文件函数(追加)
  491. '输入值:写入内容
  492. '调用示例:call QTP_WriteFile("c:\1.txt","hello world")

  493. Public Function QTP_WriteFile(pathway,words)    
  494.     Dim fileSystemObj,fileSpec,logFile,way
  495.     Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
  496.     fileSpec = pathway
  497.     Set logFile = fileSystemObj.OpenTextFile(fileSpec, 8, true)
  498.     logFile.WriteLine (CStr(words))
  499.     logFile.Close
  500.     Set logFile = Nothing
  501. End Function



  502. '写文件函数(改写)
  503. '输入值:写入内容
  504. '调用示例:Call QTP_WriteFile_Change("c:\1.txt","hellosasasaasas world")

  505. Public Function QTP_WriteFile_Change(pathway,words)    
  506.     Dim fileSystemObj,fileSpec,logFile,way
  507.     Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
  508.     fileSpec = pathway
  509.     Set logFile = fileSystemObj.OpenTextFile(fileSpec, 2, true)
  510.     logFile.WriteLine (CStr(words))
  511.     logFile.Close
  512.     Set logFile = Nothing
  513. End Function



  514. '读Excel文件元素
  515. '调用示例:cellstr=QTP_Read_Excel("c:\mytest.xls","Data",4,2) 4为行,2为列

  516. Public Function QTP_Read_Excel(pathway,sheetname,x,y)
  517.     Dim srcData,srcDoc,ret
  518.     set srcData = CreateObject("Excel.Application")
  519.     srcData.Visible = True
  520.     set srcDoc = srcData.Workbooks.Open(pathway)
  521.     srcDoc.Worksheets(sheetname).Activate
  522.     ret = srcDoc.Worksheets(sheetname).Cells(x,y).value
  523.     srcData.Workbooks.Close
  524.     Window("text:=Microsoft Excel").Close
  525.     QTP_Read_Excel = ret
  526. End Function



  527. '写Excel文件元素并保存退出
  528. '调用示例:QTP_Write_Excel("c:\mytest.xls","Data",4,2,"abcdef") 4为行,2为列

  529. Public Function QTP_Write_Excel(pathway,sheetname,x,y,content)
  530.     Dim srcData,srcDoc,sp1,sp2,num,use,a1,a2,a3
  531.     set srcData = CreateObject("Excel.Application")
  532.     srcData.Visible = True
  533.     set srcDoc = srcData.Workbooks.Open(pathway)
  534.     srcDoc.Worksheets(sheetname).Activate
  535.     srcDoc.Worksheets(sheetname).Cells(x,y).value = content
  536.     
  537.     Dim WshShell
  538.     Set WshShell=CreateObject("Wscript.Shell")
  539.     WshShell.SendKeys "^s"
  540.     wait(1)
  541.     
  542.     srcData.Workbooks.Close
  543.     Set srcDoc = nothing
  544.     
  545.     Window("text:=Microsoft Excel").Close
  546. End Function



  547. '定时停留弹出框函数
  548. '调用示例:call QTP_Msgbox("业务处理错误",2,"调试提示")

  549. Sub QTP_Msgbox(Value,waitTime,Title)
  550.     Dim WshShell
  551.     Set WshShell = CreateObject("WScript.Shell")
  552.     WshShell.Popup Value, waitTime, Title
  553.     Set WshShell = nothing
  554. End Sub



  555. '改变Excel的单元格颜色
  556. Public Function QTP_Change_Color(pathway,sheetname,x,y,color)
  557.     Dim srcData,srcDoc,sp1,sp2,num,use,a1,a2,a3
  558.     set srcData = CreateObject("Excel.Application")
  559.     srcData.Visible = True
  560.     set srcDoc = srcData.Workbooks.Open(pathway)
  561.     srcDoc.Worksheets(sheetname).Activate
  562.     If color = "red" Then
  563.         srcDoc.Worksheets(sheetname).Cells(x,y).Interior.color=vbred
  564.     ElseIf color = "green" Then
  565.         srcDoc.Worksheets(sheetname).Cells(x,y).Interior.color=vbgreen
  566.     Else
  567.         MsgBox "输入的颜色参数不正确,只接收""red""和""green"""
  568.     End If

  569.     Dim WshShell
  570.     Set WshShell=CreateObject("Wscript.Shell")
  571.     WshShell.SendKeys "^s"
  572.     wait(1)
  573.     
  574.     srcData.Workbooks.Close
  575.     Set srcDoc = nothing
  576.     Window("text:=Microsoft Excel").Close
  577. End Function



  578. '捕获当前屏幕(截图)
  579. '调用示例:call QTP_Capture("c:\")

  580. Public Function QTP_Capture(pathway)
  581.   Dim datestamp
  582.   Dim filename
  583.   datestamp = Now()
  584.   filename = Environment("TestName")&"_"&datestamp&".png"
  585.   filename = Replace(filename,"/","")
  586.   filename = Replace(filename,":","")
  587.   filename = pathway + "\" + ""&filename
  588.   Desktop.CaptureBitmap filename
  589.   Reporter.ReportEvent micFail,"image",""
  590. End Function



  591. '日志输出函数,包含三个参数
  592. '参数1:EventStatus包括 micPass,micFail,micDone,micWarning
  593. '参数2:ReportStepName,主题名称
  594. '参数3:Details,详细描述
  595. '调用示例: rep micPass,"TC00001","http://news.sina.com.cn链接成功打开"

  596. Public Function rep(EventStatus,ReportStepName,Details)
  597.     Reporter.Filter = rfEnableAll
  598.     Reporter.ReportEvent EventStatus,ReportStepName,Details
  599.     Reporter.Filter = rfDisableAll
  600. End Function



  601. '读指定文本文件指定行内容
  602. '调用示例:str=ReadLine("c:\1.txt",4)

  603. Function ReadLine(pathway, rowcount)
  604.     Dim fso,myfile,i,flag
  605.     flag = 1
  606.     Set fso=CreateObject("scripting.FileSystemObject")
  607.     If fso.FileExists(pathway) then
  608.         Set myfile = fso.openTextFile(pathway,1,false)
  609.     Else
  610.         flag = 0
  611.     End If
  612.     
  613.     For i=1 to rowcount-1
  614.         If Not myfile.AtEndOfLine Then
  615.             myfile.SkipLine
  616.         End If
  617.     Next
  618.     
  619.     If flag = 1 then
  620.         If Not myfile.AtEndOfLine Then
  621.             ReadLine = myfile.ReadLine
  622.         Else
  623.             ReadLine = "文本越界"
  624.         End If
  625.         myfile.close
  626.     Else
  627.         ReadLine = "文件不存在"
  628.     End If
  629. End Function

  630. '启动运行
  631. Sub Run()
  632.     Dim WshShell
  633.     set WshShell = CreateObject("Wscript.Shell")
  634.     WshShell.SendKeys "^{ESC}R"
  635.     Set WshShell = nothing
  636. End Sub

  637. '运行指定程序
  638. Sub RunApp(command)
  639.     Dim WshShell
  640.     set WshShell = CreateObject("Wscript.Shell")
  641.     WshShell.Exec command
  642. End Sub



  643. '值交换函数
  644. Public Sub swap(byref a,byref b)
  645.     Dim c
  646.     c = a
  647.     a = b
  648.     b = c
  649. End Sub



  650. '发送电子邮件
  651. '调用示例:call SendMail("yong_yu@jit.com.cn","自动化测试试验","自动化测试报告","c:\autotestreport.html")

  652. Function SendMail(SendTo, Subject, Body, Attachment)
  653.     Dim ol,mail
  654.     Set ol=CreateObject("Outlook.Application")
  655.     Set Mail=ol.CreateItem(0)
  656.     Mail.to=SendTo
  657.     Mail.Subject=Subject
  658.     Mail.Body=Body
  659.     If (Attachment <> "") Then
  660.         Mail.Attachments.Add(Attachment)
  661.     End If
  662.     Mail.Send
  663.     ol.Quit
  664.     Set Mail = Nothing
  665.     Set ol = Nothing
  666. End Function



  667. '启动资源管理器
  668. Sub ZYGLQ()
  669.     Dim WshShell
  670.     set WshShell = CreateObject("Wscript.Shell")
  671.     WshShell.SendKeys "^+{ESC}"
  672.     Set WshShell = nothing
  673. End Sub