473,499 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

I would like to call a function that "returned" several values

MLH
I would like to call a function that "returned" several values - all
of which are relevant to the needs of a procedure on a form. I do
understand that FN's return a single value.

I'm wondering, is this a good place to employ a user-defined Type?

The FN would reside in a global module. When called, it does return
one value considered to be the most important. But while it's running,
it does calculate several more important values that would otherwise
have to be REcalculated in the calling function when processing
returns there. Comments?
Oct 22 '07 #1
10 1532
The simplest approach is to pass some extra arguments *into* the function,
and set them in there. The calling routine can then check the value of those
variables afterwards.

A user-defined type is also a good solution for some cases. See:
Multiple return values from a Function - User-defined types
at:
http://allenbrowne.com/ser-16.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.netwrote in message
news:1a********************************@4ax.com...
>I would like to call a function that "returned" several values - all
of which are relevant to the needs of a procedure on a form. I do
understand that FN's return a single value.

I'm wondering, is this a good place to employ a user-defined Type?

The FN would reside in a global module. When called, it does return
one value considered to be the most important. But while it's running,
it does calculate several more important values that would otherwise
have to be REcalculated in the calling function when processing
returns there. Comments?
Oct 22 '07 #2
MLH <CR**@NorthState.netwrote in
news:1a********************************@4ax.com:
I would like to call a function that "returned" several values - all
of which are relevant to the needs of a procedure on a form. I do
understand that FN's return a single value.

I'm wondering, is this a good place to employ a user-defined Type?

The FN would reside in a global module. When called, it does return
one value considered to be the most important. But while it's running,
it does calculate several more important values that would otherwise
have to be REcalculated in the calling function when processing
returns there. Comments?
Public Function MyHeroes(ByVal p1, ByVal p2) As Variant
Dim a(6) As Variant
a(0) = UCase(p1)
a(1) = LCase(p1)
a(2) = StrConv(p1, vbProperCase)
a(3) = UCase(p2)
a(4) = LCase(p2)
a(5) = StrConv(p2, vbProperCase)
MyHeroes = a
End Function

Sub test()
Dim r As Variant
r = MyHeroes("giLbert a HIGHet", "harry s Truman")
Debug.Print r(0)
Debug.Print r(1)
Debug.Print r(2)
Debug.Print r(3)
Debug.Print r(4)
Debug.Print r(5)

'GILBERT A HIGHET
'gilbert a highet
'Gilbert A Highet
'HARRY S TRUMAN
'harry s truman
'Harry S Truman

End Sub

--
lyle fairfield
Oct 22 '07 #3
MLH
Thanks, Allen. In the simplest case, where only a single argument is
required for the function to do its job, there would be no need to
pass the FN additional info that would be superflous. But with that
single input, the FN may make a considerable number value assignments
along the way whilst it's doing its job. When done, it returns a
single and hopefully useful value to the calling procedure. What would
the addtional inputs do to reach the desired end?
>The simplest approach is to pass some extra arguments *into* the function,
and set them in there. The calling routine can then check the value of those
variables afterwards.
Oct 22 '07 #4
MLH
Oops. I might have err'd...
I assumed that a(6) was a variant array. But a small
addition to your code did not verify that...

Public Function MyHeroes(ByVal p1, ByVal p2) As Variant
Dim a(6) As Variant
a(0) = UCase(p1)
a(1) = LCase(p1)
a(2) = StrConv(p1, vbProperCase)
a(3) = UCase(p2)
a(4) = LCase(p2)
a(5) = StrConv(p2, vbProperCase)
MyHeroes = a
Debug.Print ".......", VarType(a), "......."

End Function

Sub test()
Dim r As Variant
r = MyHeroes("giLbert a HIGHet", "harry s Truman")
Debug.Print r(0)
Debug.Print r(1)
Debug.Print r(2)
Debug.Print r(3)
Debug.Print r(4)
Debug.Print r(5)

'....... 8204 .......
'GILBERT A HIGHET
'gilbert a highet
'Gilbert A Highet
'HARRY S TRUMAN
'harry s truman
'Harry S Truman

End Sub

I would have expected a value of 8192 - but that sure ain't
what I got. Hmmm???
Oct 22 '07 #5
MLH
Looks like its part vbVariant and vbArray
when evaluating the value returned in a
bitwise manner. Surely that's it. I mean, its
certainly not a UDT.
Oct 22 '07 #6
On Oct 22, 1:05 pm, MLH <C...@NorthState.netwrote:
Oops. I might have err'd...
I assumed that a(6) was a variant array. But a small
addition to your code did not verify that...

Public Function MyHeroes(ByVal p1, ByVal p2) As Variant
Dim a(6) As Variant
a(0) = UCase(p1)
a(1) = LCase(p1)
a(2) = StrConv(p1, vbProperCase)
a(3) = UCase(p2)
a(4) = LCase(p2)
a(5) = StrConv(p2, vbProperCase)
MyHeroes = a
Debug.Print ".......", VarType(a), "......."

End Function

Sub test()
Dim r As Variant
r = MyHeroes("giLbert a HIGHet", "harry s Truman")
Debug.Print r(0)
Debug.Print r(1)
Debug.Print r(2)
Debug.Print r(3)
Debug.Print r(4)
Debug.Print r(5)

'....... 8204 .......
'GILBERT A HIGHET
'gilbert a highet
'Gilbert A Highet
'HARRY S TRUMAN
'harry s truman
'Harry S Truman

End Sub

I would have expected a value of 8192 - but that sure ain't
what I got. Hmmm???
TTBOMK 8192 is never returned from VarType.

One hopes that you got 8204.

8192 indicates an array; 12 indicates a variant. 8192 +12=8204,

TypeName(a) returns Variant(), that is, variant array.
Oct 23 '07 #7
You can make the arguments Optional, so you don't have to pass them all.

You can pass a ParamArray(), where the number of arguments will vary at
runtime.

You can pass a Recordset, which contains all the fields as values.

You can use a user-defined type, with a structure that's akin to a
recordset.

Horses for courses.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.netwrote in message
news:7r********************************@4ax.com...
Thanks, Allen. In the simplest case, where only a single argument is
required for the function to do its job, there would be no need to
pass the FN additional info that would be superflous. But with that
single input, the FN may make a considerable number value assignments
along the way whilst it's doing its job. When done, it returns a
single and hopefully useful value to the calling procedure. What would
the addtional inputs do to reach the desired end?
>>The simplest approach is to pass some extra arguments *into* the function,
and set them in there. The calling routine can then check the value of
those
variables afterwards.
Oct 23 '07 #8
MLH
OK. Many thx.
Oct 23 '07 #9
MLH
Gotcha. I later noticed the last paragraph
in HELP indicated exactly what you said.
Oct 23 '07 #10
MLH
OK. Thx.
Oct 23 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3822
by: Sergey | last post by:
Hi, Randomly I get an error "Function returned |" while trying to upload a file in ASP application, use FileUp server- side component from SoftWare Artisans ... can't find any references to...
3
2313
by: Robert Brown | last post by:
Hi All.. What I have is a normal ASP web page wih javascript. The javascript needs to call a payment gateway, but the only way to get to it is https://paymentgateway/external.pl with parameters....
19
2758
by: Christian Engström | last post by:
If you have a function that returns something by value, the gcc compiler (version 3.2.3 on Windows XP with MinGW) converts the returned value from the type you specify in the code, to the const...
10
2586
by: LaEisem | last post by:
On-the-job, I have "inherited" a lot of old C language software. A question or two about when "casting" of null pointer constants is needed has occurred during behind-the-scenes cleanup of some...
0
991
by: Jimmy | last post by:
Hey Im calling a webservice wich is returning a DataSet. In the DataSet, wich is generated from a SQL query, there is a date field. This datefield (datetime) has the value '12-04-2004' (Danish...
2
1313
by: cesark | last post by:
I have calling a stored procedure that returns two values, and I want to catch these values and to store them into a variable. Here is a piece of my SP inside SQL Server that shows the returned...
4
1261
by: Magcialking | last post by:
Like this: Type& a=b(); I wonder if the value b returned can be refered this way.
1
2685
by: dschat | last post by:
Hi all, I am receiving: 'SQL0443N The Routine "SQLSTATISTICS" returned an error' when I try to connect to a DB2/OS390 table over MS Access. I bound the database with db2cli.lst, ddcsmvs.lst and...
160
5731
by: DiAvOl | last post by:
Hello everyone, Please take a look at the following code: #include <stdio.h> typedef struct person { char name; int age; } Person;
0
7007
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3099
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.