VBS中的ExecuteGlobal语句的使用

在VBScript中,可以用ExecuteGlobal语句来在一个脚本文件中加载另外一个脚本的函数,例如,假设需要加载的是脚本Test.vbs:
Function Test1
 Msgbox "Test1"
End Function

那么可以在脚本ExecuteGlobal.vbs中按下面的方式加载并调用Test1函数:
Set fso = CreateObject("Scripting.FilesyStemObject")
Str = fso.OpenTextFile("Test.vbs", 1).ReadAll
ExecuteGlobal Str
Set fso = Nothing

Test1


在QTP中有对应的一个函数叫ExecuteFile,可以用于替代QTP中添加Resource的方式:

If you decide not to associate a function library (any VBScript file) with a test, but do want to be able to call its functions, subroutines, and so forth from an action in your test or from another function library, you can do so by inserting an ExecuteFile statement in your action.

When you run your test, the ExecuteFile statement executes all global code in the function library making all definitions in the file available from the global scope of the action's script.

Note: You cannot debug a file that is called using an ExecuteFile statement, or any of the functions contained in the file. In addition, when debugging a test that contains an ExecuteFile statement, the execution marker may not be correctly displayed.

你可能感兴趣的:(function,脚本,VBScript,action,library,debugging)