QTP: Working with SiebCalculator

by Anshoo Arora ON August 10, 2009 · Posted In All, QTP, QTP/Siebel · 0 comments

This is the 4th article in the Siebel series. In this article, we will detail an effective way to work with the Siebel Calculator Object.

By default, a Siebel Calculator has a small set of input keys to work with. The idea is to verify that each input key is valid before processing the output through the calculator. The method IsKeyLoaded verifies if the key really exists in the calculator object (all possible keys are hard-coded in the array ‘arrFixedKeys’) whereas the method SiebCalculatorClickKeys presses the keys in an array one after the other.

Usage
Set oCalc = SiebApplication( "uiname:=MyApp" ).SiebScreen( "uiname:=MyScreen" )_
            .SiebView( "uiname:=MyView" ).SiebApplet( "uiname:=MyApplet" )_
            .SiebCalculator( "uiname:=MyCalculator" )
 
SiebCalculatorClickKeys oCalc, Array( "1", "+", "2", "-", "3", "*", "99" )

The above will simulate (1+2-3*99) in the SiebCalculator object.

How its done:
' Purpose: Checks if array of keys to be input to Calculator is valid
'
' Args:
'    arrKeys
'
' Return:
'    Boolean

Private Function IsKeyLoaded( arrKeys )
    Dim arrFixedKeys
    Dim blnExists
    Dim inKey, fixKey
 
    arrFixedKeys = Array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, "/", "CE", "*", "C", "-", "%", &_
                     "±", ".", "+", "=" )
 
    For Each inKey in arrKeys
        blnExists = False
        For Each fixKey in arrFixedKeys
            If Trim(LCase(CStr(inKey))) = Trim(LCase(CStr(fixKey))) Then
                blnExists = True
                Exit For
            End If
        Next
        If Not blnExists Then
            IsKeyLoaded = blnExists
            Exit Function
        End If
    Next
 
    IsKeyLoaded = blnExists
 
End Function
 
 
' Args:
'    oCalculator - object reference to the Calculator hierarchy
'    arrKeys - Keys to be pressed on the calculator object
'
' Output: 
'    Integer
'
' Dependancy:
'    IsKeyLoaded

Public Sub SiebCalculatorClickKeys( ByVal oCalculator, ByVal arrKeys )
    Dim i
 
    ' Check if the keys entered by the user are valid and exist as keys on the 
    '_ SiebCalculator object.
    isValid = IsKeyLoaded(arrKeys)
 
    ' The following component can be modified to also work with 'ClickKeys':
    '_ enter an array with multiple values in each element and use clickKeys if the length
    '_ is greater than 1, unless if it is the key "CE"
    If Not isValid Then
        Reporter.ReportEvent micWarning, "Invalid Key(s)", "Array: " & Join(arrKeys, ",")
    Else
        'object.OpenPopup
        For i = LBound(arrKeys) to UBound(arrKeys)
            oCalc.ClickKey arrKeys(i)
        Next
        'object.ClosePopup
    End If
 
End Sub

When the procedure ends, the output will be visible in the calculator’s output field.

Subscribe to Relevant Codes (by Anshoo Arora)

Hello! We're always posting interesting articles on Relevant Codes. Why not subscribe so you don't miss out?

Leave a Comment

{ 0 comments… add one now }

Previous post:

Next post: