分享

有关Environment Variable的一些用法

 恋家的孩子 2012-02-07
如何检查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 0
End 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 

Method2
Environment("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 dynArr
dynArr = fixedArr

Environment.Value("passArray") = dynArr

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多