to come back two values

  • Thread starter Thread starter Frank Dulk
  • Start date Start date
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.
 
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.
 
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.
 
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
 
Back
Top