Re: Can a function return two values?

From: Dana DeLouis (delouis_at_bellsouth.net)
Date: 08/13/04


Date: Fri, 13 Aug 2004 08:00:29 -0400

Here are two ideas. These can be made shorter, but I assume these are part
of something more complex.

Sub TestIt()
    Debug.Print GE(5)
End Sub

Function GE(a)
'This is the main Function
Dim v
v = ff(a)
GE = Elevation(v)
End Function

Function ff(a)
' Returns station and offset to the main function
    ff = Array(a + 1, a ^ 2 + 1)
End Function

Function Elevation(v)
    Dim Station
    Dim Offset

    Station = v(0)
    Offset = v(1)

    Elevation = Station + Offset
End Function

' Another just for ideas
'========================

Function GE(a)
'This is the main Function

Dim Station
Dim Offset
Dim Temp

Temp = ff(a)
Station = Temp(0)
Offset = Temp(1)

GE = Elevation(Station, Offset)
End Function

Function ff(a)
' Returns station and offset to the main function
    ff = Array(a + 1, a ^ 2 + 1)
End Function

Function Elevation(Station, Offset)
    Elevation = Station + Offset
End Function

As you can see, there are many ways. Just depends on what you need. One
function to change "a" to Elevation would probably be better, but it
depends...

HTH
Dana DeLouis

"Anil K." <anonymous@discussions.microsoft.com> wrote in message
news:546d01c480ac$a1328770$a401280a@phx.gbl...
> Is it possible for a function to return two values to be
> used in another function?
>
> Suppose I need a function "ff" to calculate two variables
> called "station" and "offset". Is it possible to return
> both these variables to be used in another function
> called "elevation(station, offset)"?
>
> A very rough algorithm follows -
>
> Function GE()
> 'This is the main function
> Dim a as long
>
> Call ff(a)
> GE = elevation(station, offset)
>
> End Function
>
> Function ff( var as long)
> 'Returns station and offset to the main function
>
> station = a +1
> offset = a^2+1
>
> 'How do I return both station and offset?
> ??
> End Function
>
> Function elevation (station as long, offset as long)
>
> elevation = station + offset (for simplicity)
>
> End Function
>
> THANKS IN ADVANCE.
>
>
>
>
>
>
>
>
>
>



Relevant Pages

  • Re: Can a function return two values?
    ... Dim a as long ... 'Returns station and offset to the main function ... > 'Returns station and offset to the main function ... > Function elevation ...
    (microsoft.public.excel.programming)
  • Re: Spreadsheet calculations with offsets
    ... "foot mark" on the values in your Offset column? ... New line Station of the line ... How I came up with the calculations is the following: ... like it in a cell format maybe something like this. ...
    (microsoft.public.excel)
  • Re: Can a function return two values?
    ... Dim station As Long, offset As Long ... > Function elevation ...
    (microsoft.public.excel.programming)
  • Re: Can a function return two values?
    ... ByRef is the default, so all 3 arguments (var, station & offset) are passed ... by reference. ...
    (microsoft.public.excel.programming)
  • Re: Spreadsheet calculations with offsets
    ... Same question about the "foot mark" on the values in your Offset column? ... > length of a line and the beginning and end distance. ... New line Station of the line ... How I came up with the calculations is the following: ...
    (microsoft.public.excel)