Micro Focus QTP (UFT) Forums
How to Execute Functions - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to Execute Functions (/Thread-How-to-Execute-Functions)



How to Execute Functions - tapandalal - 10-23-2008

Hi Ankur,

I am new to QTP, just started few days back,

I understood the concept of functions that you explained.

Now whatever the functions that I am creating if i want to see the ouput of that function, how I can see that.

exapmple: Function sum (val1,val2)
sum = val1 + val2
End Function.

now I know that if I call this function in my script i have to give value to my arguments val2 and val2. but

(1)how to check that whatever the function I created is giving me the correct value?

(2) Do i have to create new test and then just call this function, if this is the cade then how I call the function in the test and then what statement i use to execute that script?

please guide me with your best.

Thanks
Tapan Dalal


RE: How to Execute Functions - Brian3 - 10-23-2008

Hi Tapan,

Put your function in a function library and associate this library to your script. Then in your script, lets assume you have two variables that you wish to be added together, variable1 and variable2. To do this just add the following line in your code -

Code:
call sum (variable1,variable2)


but if you wish to check the answer -
Code:
variable3 = sum(variable1,variable2)
msgbox variable3


Hope this helps,
Brian


RE: How to Execute Functions - anemuday - 10-23-2008

Hey guys,

Dont break your head for small things. Just go for basic programmings for w3schools or any other E-Books.

Here i am giving the example required for you:

Code:
a=10
b=5
sumOfNumbers=sum(a,b)   'Here i am calling the sum function
MsgBox(sumOfNumbers)

Function sum(var1,var2)
    Dim temp
    temp=var1+var2
    sum=temp 'Here i am returning the value to the called function
End function

Let me know if you need any clarification here.

Thanks & Regards,
Uday.


RE: How to Execute Functions - tapandalal - 10-23-2008

Hi Thanks,

Actually i got that answer yesterday itself, I was doin exactly the same thing you mentioned, but did not put msgbox, then I found that from QTP help, you can also do bu putting Print statement.

onemore thing Brian, I read your thread on Siebel Application issue, I am doing the same thing, need to work on Siebel Emsedical, I want to do the same thing means everytime when you runt the scrip I need to provide new Data to Siebel App, did you find any better solution for this...

If you have the code just for one Example: Client Name that will be good for me.

Thanks in Advance

Thanks
Tapan Dalal