Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating an object via Function Library
#1
Solved: 10 Years, 8 Months, 3 Weeks ago
Hi,

Is it possible to create a description of an object via a function from the function library? I'm trying to get this code to work properly, but I keep getting the error: "Wrong number of arguments or invalid property assignment." The description of the objTextbox is created when I call the function, but it returns back to the action as Empty. Can anyone help?

This is the code from the action, Flight_NewSale:
Code:
Public objTextbox

' Create the instances of the objects in the form
txtName = createTextbox("attached name", "Arrival Time:")

And then here's the code from the Function Library:
Code:
Public Function createTextbox(nameProperty, valProperty)
  On Error Resume Next

  ' Create a textbox object
  Set objTextbox = Description.Create()
  objTextbox("Class Name").Value = "WinEdit"
  objTextbox(nameProperty).Value = valProperty

  ' Return the object
  createTextbox = objTextbox ' object is created but is returned as Empty
  If Err <> 0 Then
     msgbox Err.Description
  End If
End Function
Reply
#2
Solved: 10 Years, 8 Months, 3 Weeks ago
Hi,
You can create an objects description by using Description object. example is given below

Code:
Dim oDesc        'Description Object
Dim colObject    'Object Collection

Set oDesc = Description.Create
'Remember to always use 'micclass' and not 'class name'
oDesc( "micclass" ).value = "Browser"

'We used Desktop as the parent here because, the Desktop Object holds all the Windows
Code:
Set colObject = Desktop.ChildObjects( oDesc )
Reply
#3
Solved: 10 Years, 8 Months, 3 Weeks ago
Hi,

Please find the below code 4 refrence:

Code:
Set vo_ResDesc=createDescription("Link",DataTable("REScreateexport",dtGlobalSheet))


Function createDescription(vs_micClass,vs_Text)

   '_________________________________________________________________

'   Function: createDescription
'   Project: OCM
'   Library: Thales Functional Library
'   Description: This function will create the Description for the specified object
   '_________________________________________________________________

   'Variable Declaration:
   Dim vo_ResDesc
  

   '___________________________________________________________________

   'Code:
   Set vo_ResDesc=Description.Create()
   vo_ResDesc("micclass").value=vs_micClass
   vo_ResDesc("text").Value=vs_Text
   Set createDescription=vo_ResDesc
  

  
End Function

Let me know in case of any help required.

Regards,
Sankalp
Reply
#4
Solved: 10 Years, 8 Months, 3 Weeks ago
Thanks, I tried using your code as reference, like so:

Code from action, Flight_NewSale:
Code:
Public txtName
...
Set txtName = createObject("WinEdit", "Arrival Time:")

Code from function library, createObject:
Code:
Public objInst
...
Public Function createObject(typeObject, valProperty)
    Dim objInst ' as Object
    Set objInst = Description.Create()

    Select Case typeObject
        Case "WinEdit":
            objInst("Class Name").Value = "WinEdit"
            objInst("attached text").Value = valProperty
        Case "WinButton":
            objInst("Class Name").Value = "WinButton"
            objInst("text").Value = valProperty
    End Select

    Set createObject = objInst
End Function

But I get this error: ActiveX component can't create object: 'WinEdit':
Code:
Set txtName = createObject("WinEdit", "Arrival Time:")

When I check the values of the objects in watch, it says there that both txtName and objInst are empty. Since I'm really new to QTP, may I just confirm, are the codes you posted above both located in the function library (or both located in the action script), or are they from different locations (the line:

Code:
Set vo_ResDesc=createDescription("Link",DataTable("REScreateexport",dtGlobalSheet))

is found only in the action script and the function createDescription is located at the function library)?
in the action script, and the rest of the function createDescription in the


Thanks, tip about the micclass has been noted. However, I do know how to create descriptions of objects. What I want to know is, if I can create the descriptions of the objects using a function from the function library.
Reply
#5
Solved: 10 Years, 8 Months, 3 Weeks ago
Solved it. Again, thanks sshukla12!

Code:
Public frmFlightReservation
Set frmFlightReservation = createDescription("Window", "Flight Reservation", "", "")

Code:
Public Function createDescription(typeObject, valProperty, auxProperty, auxPropertyVal)
    '================================================
    ' Description: Form object instantiation function
    '================================================
    ' Parameters:
    '    typeObject = MICClass/Class name of the Object
    '    valProperty = Value of the text/attached text
    '    auxProperty = Object's other specified optional property (Optional)
    '    auxPropertyVal = Value of the object's other specified optional property (Optional)
    '================================================
    ' Code START!

        Set objInst = Description.Create()

        objInst("micclass").Value = typeObject
    
        Select Case typeObject
            Case "Window":
                objInst("text").Value = valProperty
            Case "Dialog":
                objInst("text").Value = valProperty
            Case "WinComboBox":
                objInst("attached text").Value = valProperty
            Case "WinButton":
                objInst("text").Value = valProperty
            Case "WinRadioButton":
                objInst("text").Value = valProperty
            Case "WinEdit":
                objInst("attached text").Value = valProperty
            Case "WinList":
                objInst("attached text").Value = valProperty
        End Select
    
        If auxProperty <> "" And auxPropertyVal <> "" Then
            objInst(auxProperty).Value = auxPropertyVal
        End If
    
        Set createDescription = objInst
End Function
Reply
#6
Solved: 10 Years, 8 Months, 3 Weeks ago
U r always welcome. Wink

Regards,
Sankalp
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling a function in a Test Script from a function library anupam4j 3 5,888 06-26-2015, 12:31 AM
Last Post: babu123
  Using QTP features in Function library TurtleRock 0 1,644 01-30-2014, 06:02 PM
Last Post: TurtleRock
  QTP is not recognizing Function Library Path associated to the test AshokReddy 2 3,947 12-19-2013, 01:59 PM
Last Post: AshokReddy
  Accessing Environment variable value in Library file vishruth143 1 2,460 09-07-2013, 05:11 AM
Last Post: jacosta
  Creating Random String SomeIntern 0 4,756 08-21-2013, 09:10 PM
Last Post: SomeIntern

Forum Jump:


Users browsing this thread: 1 Guest(s)