Results 1 to 5 of 5

Thread: how to return value from a function in QTP?

  1. #1
    Expert Member
    Join Date
    Jun 2008
    Answers
    204

    how to return value from a function in QTP?

    below is giving error: Please correct them

    msgbox getSomething()

    A return type must be declared?

    Function getFlatRate()
    s = browser("B").Page("p").WebElement("we").GetROProperty("something")
    return s
    End Function


  2. #2
    Junior Member
    Join Date
    Jul 2007
    Answers
    14

    Re: how to return value from a function in QTP?

    Hi try this,declair !
    dim c
    if c = window("flight reservation").winbutton("flight").getroproperty("flight") then
    window("flight reservation").winbutton("flight").click
    if c = c then
    reporter.reportevent micpass,"flight button enabled ","clicked"
    else
    reporter.reportevent micfail,"flight button enabled","failed to clicked"
    end if
    end if

    Last edited by Fahed9090; 07-17-2008 at 05:46 PM.

  3. #3
    Contributing Member
    Join Date
    Oct 2007
    Answers
    30

    Re: how to return value from a function in QTP?

    Just assign the value to be passed outside to the function name as below. Also for multiple variable outputs from functions use Call by Reference method.

    msgbox getFlatRate()

    Function getFlatRate()
    s = browser("B").Page("p").WebElement("we").GetROProperty("something")
    getFlatRate= s
    End Function


  4. #4
    Expert Member
    Join Date
    Jan 2007
    Answers
    211

    Thumbs up Re: how to return value from a function in QTP?

    Quote Originally Posted by learqtptesting View Post
    below is giving error: Please correct them

    msgbox getSomething()

    A return type must be declared?

    Function getFlatRate()
    s = browser("B").Page("p").WebElement("we").GetROProperty("something")
    return s
    End Function

    msgbox getFlatRate()

    Function getFlatRate()
    s = "Test"
    getFlatRate=s
    End Function


    Regards,
    Nawab

    Last edited by NawabShaikh; 07-18-2008 at 01:03 AM. Reason: Code Alteration

  5. #5
    Contributing Member
    Join Date
    Oct 2007
    Answers
    30

    Re: how to return value from a function in QTP?

    dim s
    call getFlatRate(s)
    msgbox s

    Function getFlatRate(s)
    s = "Test"
    End Function


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact