How to pass an object as parameter and use that object in function

743 views
Skip to first unread message

tarun jain

unread,
Aug 28, 2011, 9:15:10 AM8/28/11
to Karthik QTP, QTP eLearn Team
Hi All,

I have created an object.

Dim Gmail_Home
Set Gmail_Home = Browser("title:=Gmail: Email from Google").Page("title:=Gmail: Email from Google")

Also, i have a function named clicklink as below:

Function clicklink(fText,myP)
    Dim myO
    Set myO = description.Create()
    myO("micClass").value = "Link"
    myO("html tag").value = "A"
    myO("text").value = ftext
    myO("index").value = 0
       wait(2)
       if myP.link(myO).Exist(1) then
            'myP.link(myO).highlight
            myP.link(myO).Click
            wait(10)
            clicklink = True
        else
            clicklink = False
        end if
    Set myO = Nothing
End Function

Now if i called function like
clicklink("gmail",byval Gmail_Home)

But i guess this will not work. Can anybody please help me to get a way, that how can i pass an object as parameter and use that object in function.

--
Thanks & Regards

TARUN JAIN
Mobile:- 9717229000

Emad - QTP Engineer

unread,
Aug 28, 2011, 11:03:57 AM8/28/11
to tarun jain, Karthik QTP, QTP eLearn Team

Did you declare
myP

tarun jain

unread,
Aug 28, 2011, 12:40:36 PM8/28/11
to Emad - QTP Engineer, Karthik QTP, QTP eLearn Team
i tried with that also..  updated function

Function clicklink(fText,myP)
 Dim myO, myP
 Set myP = Browser("title:=.*").Page("title:=.*")

 Set myO = description.Create()
 myO("micClass").value = "Link"
 myO("html tag").value = "A"
  myO("text").value = ftext
 myO("index").value = 0
 wait(2)
 if myP.link(myO).Exist(1) then
 'myP.link(myO).highlight
 myP.link(myO).Click
  wait(10)
 clicklink = True
 else
 clicklink = False
 end if
 Set myO = Nothing
 End Function

Emad - QTP Engineer

unread,
Aug 28, 2011, 1:14:24 PM8/28/11
to tarun jain, Karthik QTP, QTP eLearn Team
Copy this

Function clicklink(fText, myP)
Option Explicit

 Dim myO, myP
 Set myP = Browser("title:=.*").Page("title:=.*")

 Set myO = description.Create()  <<<<<<< notice you SET myO = something

myP = what?

tarun jain

unread,
Aug 28, 2011, 1:47:34 PM8/28/11
to Emad - QTP Engineer, Karthik QTP, QTP eLearn Team
I'm so sorry.. myP is the object description that we created and passed to the function. plz see in the first mail i sent,

Many thanks... kindly provide some solution. its very urgent..

Emad - QTP Engineer

unread,
Aug 28, 2011, 3:29:15 PM8/28/11
to tarun jain, Karthik QTP, QTP eLearn Team
I am trying but not successful so far.

Chandan

unread,
Aug 29, 2011, 1:31:57 AM8/29/11
to QTP eLearn Team
Hi Tarun

My advice would be to make it simple first, rather than passing the
object, just create the object in the same function and use it or the
other way, put all of the code out of the function in the script and
use it. There could be an issue with the Descriptive programming that
those properties you are assigning are not sufficient and passing
object is not an issue.
Sorry, can't try and fix this as Gmail is banned at work..

Regards,
Chandan

On Aug 29, 5:29 am, Emad - QTP Engineer <qa123...@gmail.com> wrote:
> I am trying but not successful so far.
>
>
>
>
>
>
>
> On Sun, Aug 28, 2011 at 12:47 PM, tarun jain <mca.ta...@gmail.com> wrote:
> > I'm so sorry.. myP is the object description that we created and passed to
> > the function. plz see in the first mail i sent,
>
> > Many thanks... kindly provide some solution. its very urgent..
>
> > On Sun, Aug 28, 2011 at 10:44 PM, Emad - QTP Engineer <qa123...@gmail.com>wrote:
>
> >> Copy this
>
> >> Function clicklink(fText, myP)
> >> Option Explicit
>
> >>  Dim myO, myP
> >>  Set myP = Browser("title:=.*").Page("title:=.*")
>
> >>  Set myO = description.Create()  <<<<<<< notice you SET myO = something
>
> >> myP = what?
>
> >> On Sun, Aug 28, 2011 at 11:40 AM, tarun jain <mca.ta...@gmail.com> wrote:
>
> >>> i tried with that also..  updated function
>
> >>> Function clicklink(fText,myP)
> >>>  Dim myO, myP
> >>>  Set myP = Browser("title:=.*").Page("title:=.*")
>
> >>>  Set myO = description.Create()
> >>>  myO("micClass").value = "Link"
> >>>  myO("html tag").value = "A"
> >>>   myO("text").value = ftext
> >>>  myO("index").value = 0
> >>>  wait(2)
> >>>  if myP.link(myO).Exist(1) then
> >>>  'myP.link(myO).highlight
> >>>  myP.link(myO).Click
> >>>   wait(10)
> >>>  clicklink = True
> >>>  else
> >>>  clicklink = False
> >>>  end if
> >>>  Set myO = Nothing
> >>>  End Function
>
> >>> On Sun, Aug 28, 2011 at 8:33 PM, Emad - QTP Engineer <qa123...@gmail.com
> >>> > wrote:
>
> >>>> Did you declare
> >>>> myP

tarun jain

unread,
Aug 29, 2011, 6:31:55 AM8/29/11
to Chandan, QTP eLearn Team, Karthik QTP
Hi All,
 
To be more specific.
 
I'm using Karthik's framework. Now instead of passing the value for the object to create in function library(like we pass ftext in clicklink), i want to pass the complete object description through excel. and the same object was defined in the OR.vbs file.
 
My worry is when the object value is verified at run-time using debugger, the object is passed as string instead of object. I need that as an object.
 
Karthik,
Can you please look into the issue and help me asap.
 
I need some solution urgently.
 
Thanks,
Tarun Jain

Raju

unread,
Sep 6, 2011, 8:53:08 PM9/6/11
to QTP eLearn Team
Tarun,

Did you find a solution to pass an object as parameter, let us know..
Thanks !!
Raju.

On Aug 29, 6:31 am, tarun jain <mca.ta...@gmail.com> wrote:
> Hi All,
>

tarun jain

unread,
Sep 7, 2011, 12:26:20 PM9/7/11
to Raju, QTP eLearn Team
Use the concept of External Environment Variables. These are treated as global variables.

Thanks,
Tarun Jain

Brinda R

unread,
Sep 7, 2011, 1:08:03 PM9/7/11
to tarun jain, Raju, QTP eLearn Team
Hi Tarun and All,

I tried the same code which you posted in your first mail and i guess it is working. 
Tarun are you getting any error while running this code or something else?

And also you have mentioned using External Envt Variables....Can you please let us know how you resolved.

Thanks,
Brinda
Reply all
Reply to author
Forward
0 new messages