Search code examples
hp-uft

TypeOf implementation in HP UFT vba


Looking for HP-UFT VBA code that implements something similar to VB TypeOf or Java instanceOf (Java)

An example: i have an object in my repository that has a Class "WebEdit" and i want to write a sub procedure to perform an action on it, but first i want to check that the provided object is a webedit

For example here is the sub procedure i want to

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

Solution

  • From the parameters passed, I have assumed that you already have added the object to your Object Repository. Rewriting your sub as:

    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