八犬传图片人物合照:有关Environment Variable的一些用法

来源:百度文库 编辑:偶看新闻 时间:2024/04/28 04:55:02
如何检查Environment Variable是否存在
Public Function IsEnvExist(ByVal varName) IsEnvExist = True
On Error Resume Next
Dim envVal envVal = Environment(varName)
If err.number<>0 Then
IsEnvExist = False End If
On Error Goto 0End Function
msgBox IsEnvExist("Invalid")

有关Environment Variable被赋值
If we try to use Set to assign an object to the Environment Variable, 'Type mismatch' exception is raised.
1. use a string definition of the object and then convert it to an object 2. assign the object to the variable without using the Set
Method 1
Environment("BrowserObj") = "Browser(""creationtime:=0"")"
Dim objBrowser
Excute "set objBrowser = "& Environment("BrowserObj")
objBrowser.close 
Method2Environment("BrowserObj") = Browser("creationtime:=0")Dim objBrowser
set objBrowser =  Environment("BrowserObj")
objBrowser.close 
How an array is passed using Environment Variable
QTP throws a "this array is fixed or temporarily locked" exception, if we try to pass a fixed length array using Environment Variable.
Dim fixedArr(3)
For i = LBound(fixedArr,1) to UBound(fixedArr,1)     fixedArr(i) = Cstr(i)Next
Dim dynArrdynArr = fixedArr
Environment.Value("passArray") = dynArr