2017-08-01 44 views
0

寻找HP-UFT VBA代码实现类似VB TypeOf运算或Java}这种(Java)的东西在HP UFT VBA TypeOf运算执行

一个例子:我在我的库中的对象,有一个类“WebEdit”和我想要写的子过程来执行在其上的作用,但首先我要检查所提供的对象是webedit

例如这是我想

setIfNotBlank(
    Browser("Google").Page("Search").WebEdit("SearchText") 
    , "Cute kities who actually rule the world" ) 

Sub setIfNotBlank(object , val) 
    if not (object TypeOf WebEdit) 
     exit sub 'only proceed if WebEdit object 
    End if 
    object.set val 
End Sub 

回答

1

从子过程通过参数,我假设你已经有广告将对象定义到对象存储库。重写您的子文件为:

Sub setIfNotBlank(object , val) 
    If IsObject(object) then    'First checking if the parameter "object" is actually an object 
     If strComp(object.getToProperty("Class Name"),"WebEdit",1)=0 then 'Checking the value of its property "class Name". It should be "WebEdit" 
      object.Set val 
     Else 
      Exit Sub      'If "object" is not of type "WebEdit", then Exit Sub     
    Else 
     Exit Sub       'If parameter "object" is not an object, Exit Sub 
    End If 
End Sub