468,134 Members | 1,254 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,134 developers. It's quick & easy.

Need to return multiple values via same function using VB6

I want to return values of two arguments through a function via same argument.

Example:

(a, b) = getvalue(x, y)

Can anyone help?



T. Ashok Kumar
Jul 29 '07 #1
4 12000
A function can only return a single value but if you were to concatenate the two values that you want to return eg-
value1 & ", " & value2
so if you pass in (x, y) and you get back "24, 25" - note the result will be a string.
Jul 30 '07 #2
You could pass the variables you want the function to write to by reference. (Change the function to a sub).

for example

Sub Add(a as single, b as single, ByRef c as single, ByRef d as single)

c=a+b
d=b+c

End Sub

The following code would change the values of c and d to a+b and b+c respectively.
This kind of acts like a pointer in C. Instead of sending a value to the function
it sends a address so that the program can modify the value directly...
Jul 30 '07 #3
Killer42
8,434 Expert 8TB
A function can only return a single value but if you were to concatenate the two values that you want to return eg- ...
Are you sure about that? I have a feeling it might be possible for a function to return an array. Or a variant, which can contain an array.
Jul 30 '07 #4
Killer42
8,434 Expert 8TB
You could pass the variables you want the function to write to by reference. (Change the function to a sub).
for example
Sub Add(a as single, b as single, ByRef c as single, ByRef d as single) ...
Just wanted to point out, arguments are passed by reference by default in VB. You only need to specify if you want to pass them by value. In other words, while you might sometimes code the ByVal keyword, there is really no need for ByRef.

As an example, these two definitions produce the same result...
Expand|Select|Wrap|Line Numbers
  1. Sub Add(a As Single, b As Single, c As Single, d As Single)
  2. Sub Add(a As Single, b As Single, ByRef c As Single, ByRef d As Single)
Jul 30 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

66 posts views Thread by Darren Dale | last post: by
2 posts views Thread by TSK | last post: by
5 posts views Thread by D. Shane Fowlkes | last post: by
16 posts views Thread by Nikolay Petrov | last post: by
21 posts views Thread by Johan Tibell | last post: by
18 posts views Thread by SpiralCorp | last post: by
Dormilich
2 posts views Thread by Dormilich | last post: by
27 posts views Thread by didacticone | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.