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

Hi all, Recently i faced this question in infosys What is QTP architecture?? Is Architecuture and Framework are same?? Can someone please give clear understanding of this.

3 Answers   Infosys,


If you are using descriptive programming and you have two objects with the same name, so you are identiying them by name and index, how can you avoid errors if a third object with the same name is added at the begining of the page?

4 Answers  


Suppose Object name was changed in the application in the second build.I have just modified the name in the Object repository as changes in the Application. Is it possible to accure changes in the script accordingly? If so Suppose I am calling the script through function, Will the changes affect in the script(which is in the function)automatically? If not affected, tell me the solution,How to handle this. How should I change the object property name while using functions

4 Answers   Livetek,


in a web page How to check and display a particular word from a paragraph?

0 Answers  


the develeper not accepter your defect what status is that ?

1 Answers  






How to retrive data from a data table which is in 3rd row,4th column and place it in main script..like retrive name,date from data table..write script for this.

11 Answers   Thatavarti Technologies,


Explain abt the File System Object in QTP with ex

3 Answers   Ordain Solutions,


what is advantage of descripting programming in QTP?

3 Answers   ADP,


Q) Please any body can help me how we can create descriptive programming if the application is not ready i.e we don't have unique property of object ? note:build not ready means we can't use object spy in build to get unique property .

2 Answers  


How we test the logo or images in the web page using QTP? For example take google page, they change their logo for new year,christmas etc..How we test that? Plz answer this question... Thanks in advance..

2 Answers  


Recovery Manager means..?

4 Answers  


What is the diff between doing parametarisation using Data Driven wizard or manually. when do we go for manual para...and when do we use Data driver wizard..can anybody answer it ..Thanks in advance

6 Answers   Siemens,


Categories