Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Unable to return value from a user-defined function to the calling Test
#1
Solved: 11 Years, 4 Months, 3 Weeks ago
[/align]Using the Insert->Function Definition Generator i created a new function mysum with two variables var1 and var2 (both having passmode = By value)

I want this function to add the 2 variables and return the sum to the calling test.

code for the function:
Code:
Public Function mysum(var1, var2)
       ' TODO: add function body here
       sum=var1+var2
       msgbox(var1 & "+" & var2 & "=" & sum)
       return(sum)
End Function

TestCode:
Code:
sum=mysum(1,2)
Reporter.ReportEvent micPass, "ReportStepName Pass", "Sum=" &sum

Result:
I get a Type mismatch error. I tried all combinations of function definitions like: e.g. int Public Function mysum(var1, var2) but i still get the type mismatch error.
Reply
#2
Solved: 11 Years, 4 Months, 3 Weeks ago
Hi Richa,

Use the below code, return is not the valid syntax

Code:
Public Function mysum(var1, var2)
' TODO: add function body here
Dim sum
sum=var1+var2
msgbox(var1 & "+" & var2 & "=" & sum)
mysum = sum
End Function


sum=mysum(1,2)
msgbox  "Sum=" &sum
Reply
#3
Solved: 11 Years, 4 Months, 3 Weeks ago
Thanks...

But this is strange... So if one wants to return values, it has to be stored in a variable name same as that of the function.

Whats the logic behind this? could u explain?

And what is the datatype of this mysum variable?
Reply
#4
Solved: 11 Years, 4 Months, 3 Weeks ago
That is the logic for VB Scripting. For C language, you can use return to get the returning result from a function.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  UFT 12.02 Compatibility for IE 11.0 : Fail to identify the defined Object Amruta_121 9 11,282 01-11-2016, 12:45 PM
Last Post: vinod123
  Childobject return wrong checkbox count.. VpnQTP 1 2,888 04-09-2015, 09:07 PM
Last Post: babu123
  Calling a Function in Function Library when function is defined in an Action jitenderkkr 0 3,034 11-27-2014, 12:53 PM
Last Post: jitenderkkr
  calling QTP script from one to another krishnas.tester 3 6,807 11-12-2014, 10:32 AM
Last Post: vinod123
  calling stored procedure from Oracle borisk 3 6,516 03-19-2013, 12:41 PM
Last Post: gaveyom

Forum Jump:


Users browsing this thread: 1 Guest(s)