Is it possible to return multiple values from a function..?
Then how..?

Answers were Sorted based on User's Feedback



Is it possible to return multiple values from a function..? Then how..?..

Answer / satish j

It is possible to return multiple values from a function?
Here I am taking the return values in an array and using
them as I want

mynum1 = 0
mynum2 = 0
dim linklist(2)
imax = ubound(linklist)

Function fncl1(ByRef mynum1,mynum2, x , y)
If i= 0 Then
z = "+"
Select Case z
case "+"
mynum1 = x +y
msgbox mynum1
fncl1 = mynum1
End select
else
z = "-"
Select Case z
case "-"
mynum2 = x- y
msgbox mynum2
fncl1 = mynum2
End Select
end if
End Function

For i=0 to imax
linklist(i) = fncl1(mynum1,mynum2,5,4)
If linklist(i) = mynum2 Then
Exit for
End If
Next

msgbox linklist(0)+linklist(1)
msgbox linklist(0)&","&linklist(1)

Is This Answer Correct ?    2 Yes 0 No

Is it possible to return multiple values from a function..? Then how..?..

Answer / rico

One way of getting mutiple values from function is by
passing values "ByRef" to the funtion and storing the
return values in the one or more arguemnts passed to the
functions.

Ex :
mysum = 0
msgbox mysum ' return 0
mysub = 0
msgbox mysub ' return 0

Function fnmul(byref mysum, mysub, x , y)

mysum = x + y
msgbox mysum 'return 9
mysub = x - y
msgbox mysub 'return 1

End Function

Call fnmul( mysum, mysub, 5, 4)

msgbox mysum 'return 9

msgbox mysub 'return 1

Is This Answer Correct ?    3 Yes 2 No

Is it possible to return multiple values from a function..? Then how..?..

Answer / rico

If we pass the parameters by "Byval" the last two msgbox
statement will return "0"

Ex :
mysum = 0
msgbox mysum ' return 0
mysub = 0
msgbox mysub ' return 0

Function fnmul(byval mysum, mysub, x , y)

mysum = x + y
msgbox mysum 'return 9
mysub = x - y
msgbox mysub 'return 1

End Function

Call fnmul( mysum, mysub, 5, 4)

msgbox mysum 'return 0

msgbox mysub 'return 0

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More QTP Interview Questions

When I start recording any web application (either Mozilla or IE) QTP recognizes window instead of browser and also it does not show all the hierarchy tree of that particular web page. 1. Window("Mozilla Firefox").Check CheckPoint("Mozilla Firefox") 2. As everybody knows it should be browser("Mozilla Firefox").Check CheckPoint("Mozilla Firefox") I am using the windows vista, do you think it may be a problem of my settings in QTP or problem of my installation. Your kind responses will be appreciated. Thanks in advance. Satya

12 Answers  


If the object property is changing very frequently, what was your approach?

2 Answers  


if devloper change only button names in present build then script will execute or not , why? Only gui changed.......

2 Answers   Cap Gemini,


I want to learn Advanced QTP, suggest me the best faculty in Hyderabad

12 Answers  


How to find the number the number of Links, Brolken Links in a webpage?

3 Answers   Ordain Solutions,






I register user defined function in one test, I tried to call that function into other test. But that function not works in other test please give the direction for that.

1 Answers  


What is the synchronization point in qtp?

0 Answers  


Can i run the qtp, without OBJECT REPOSTIRY...

8 Answers  


How to associate shared object repository to test in qtp?

0 Answers  


Hi,The question is write a script for the following scenario. scenario:in a job portal i entered QTP 3yrs testing then click search button.then it displays results like Test lead bangalore (here is a checkbox). Test lead hyderabad check box so on... question is if test lead position in bangalore then checkbox shld be enabled automatically..

4 Answers   Thatavarti Technologies,


how do you remove object repository at runtime and load object repository and verify it

2 Answers   Thomson Reuters,


What is the ur roles and responsibilities as automation testing engineer?

2 Answers   Atos Origin,


Categories