472,975 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,975 software developers and data experts.

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 12377
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,435 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,435 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

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

Similar topics

66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
2
by: TSK | last post by:
I cannot get my focus() fn to work in my validateInput(userInput) fn. It will not allow the user to go back and correct invalid input like it should. Instead it goes right on through with the...
5
by: D. Shane Fowlkes | last post by:
This may be a very basic question but it's something I've never done before. I've looked at a couple of my favorite sites and books and can't find an answer either. I can write a Function to...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
5
by: Ghislain Tanguay | last post by:
Hi! I'm maybe from old school but, for me, whebn it's time to call a method from DCOM, remoting or web service returning a string or anything else I use a function. It's more verbose. In my new...
18
by: Ed Jay | last post by:
<disclaimer>js newbie</disclaimer> My page has a form comprised of several radio buttons. I want to poll the buttons to determine which button was selected and convert its value to a string. I...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
18
by: SpiralCorp | last post by:
int divide (int a, int b) { int r; r=a/b; return (r); } int main () { int result = divide (20,4); cout << result
2
ADezii
by: ADezii | last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum. Original Article by Allen Browne ...
2
Dormilich
by: Dormilich | last post by:
Hi, I'm testing my classes for a web page and I stumble upon an error I don't have a clue what it means: Error: Fatal error: Can't use method return value in write context in "output.php" on...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.