Micro Focus QTP (UFT) Forums

Full Version: No value is returned to function call line
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When I call a function which should return true/false it doesn't seem to return any value. The value is printed out to the report in the function itself.

Test file where I call the function:
Code:
TestFunction sMenuClick, noMenuVal
Reporter.ReportEvent micPass, "Test Function", "TestFunction: " & TestFunction


Function file:
Code:
Function TestFunction (sMenuClick, noMenuVal)
  If 1+1 = 2 Then
    TestFunction = true
    Reporter.ReportEvent micPass, "INSIDE Test  Function", "TestFunction: " & TestFunction
  End If
End Function


I get a general run error in the Reporter line where I try to write the TestFunction value to the report. I guess it's a simple thing I'm forget, do you see what could be wrong?
Here you go:

Code:
x = TestFunction (sMenuClick, noMenuVal)
Reporter.ReportEvent micPass, "Test Function", "TestFunction: " & x

'Function file:
Code:
Function TestFunction (sMenuClick, noMenuVal)
If 1+1 = 2 Then
TestFunction = true
Reporter.ReportEvent micPass, "INSIDE Test Function", "TestFunction: " & TestFunction
End If
End Function

You forgot to assign the return value to a variable. Next time please format the code while posting a query.
Here are 2 ways to fix the issue. I hope this helps.

1.**************Here you are calling the function in the reporter statement
Code:
Reporter.ReportEvent micPass, "Test Function", "TestFunction: " & TestFunction( sMenuClick, noMenuVal )

Function TestFunction (sMenuClick, noMenuVal)
    If 1+1 = 2 Then
    TestFunction = true
    Reporter.ReportEvent micPass, "INSIDE Test Function", "TestFunction: " & TestFunction
    End If
End Function

2. **********here you store the result of the function into a variable and then use the variable in the reporter statement
Code:
TestResult = TestFunction (sMenuClick, noMenuVal)
Reporter.ReportEvent micPass, "Test Function", "TestFunction: " & TestResult

Function TestFunction (sMenuClick, noMenuVal)
    If 1+1 = 2 Then
    TestFunction = true
    Reporter.ReportEvent micPass, "INSIDE Test Function", "TestFunction: " & TestFunction
    End If
End Function
Thanks for your answers, Ankur and swat2008! I knew that it was an easy thing I had forgot. I promise to format my pasted code next time.