to come back two values

F

Frank Dulk

As I do for a function to come back two values, for instance:
Function TTotal ()

Dim A, B, C, D As Integer
Dim SomaA, SomaB as Integer

A = 1
B = 2
C = 3
C = 4

SumA = A + B
SumB = C + D

I would have a Field where would place
Field1 = SumA
Field2 = SumB

I don't know if you understood the idea, I want a function to come back two
values and that I can use those values in different fields.
And I forgot how I do to call a procedure starting from other.
At once I thank the attention.
 
M

MyndPhlyp

Frank Dulk said:
As I do for a function to come back two values, for instance:
Function TTotal ()

Dim A, B, C, D As Integer
Dim SomaA, SomaB as Integer

A = 1
B = 2
C = 3
C = 4

SumA = A + B
SumB = C + D

I would have a Field where would place
Field1 = SumA
Field2 = SumB

I don't know if you understood the idea, I want a function to come back two
values and that I can use those values in different fields.
And I forgot how I do to call a procedure starting from other.
At once I thank the attention.

Functions are limited to returning a single value, if I'm not mistaken.

Some workarounds:

* Global variables.

* Subroutines with parameters passed ByRef instead of ByVal.

* Have the Function return an Array.
 
F

Frank Dulk

Could happen an example?

MyndPhlyp said:
Functions are limited to returning a single value, if I'm not mistaken.

Some workarounds:

* Global variables.

* Subroutines with parameters passed ByRef instead of ByVal.

* Have the Function return an Array.
 
J

John Spencer (MVP)

Declare a variable (or variables) and pass that in byRef. If you do that your
routine can update the varible you passed in.

Sub fGetValues()
Dim SumA as Integer
Dim SumB as Integer

Function fTotal SumA, SumB

Field1 = SumA
Field2 = SumB

End Sub


Public Function fTotal (ByRef SumA, ByRef SumB)

Dim A, B, C, D As Integer

A = 1
B = 2
C = 3
D = 4

SumA = A + B
SumB = C + D
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top