Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Can a function return two values?

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.










  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default Can a function return two values?

Instead of using the result of the function, simply pass the parameters by
value

Function GE()
'This is the main function
Dim a as long


call ff(a,station,offset)
GE = elevation(station, offset)

End Function


Function ff( var1, var2, var3)
'Returns station and offset to the main function

var2 = var1 +1
var3 = var1^2+1
End Function


"Anil K." wrote in message
...
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 -

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.












  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Can a function return two values?

Here is an example

Function GE()
Dim a As Long
Dim station As Long, offset As Long

station = 1
offset = 2
a = 3
Call ff(a, station, offset)

MsgBox station & ", " & offset
GE = elevation(station, offset)
MsgBox GE

End Function

Function ff(var As Long, ByRef station As Long, ByRef offset As Long)

station = var + 1
offset = var ^ 2 + 1

End Function

Function elevation(station As Long, offset As Long)

elevation = station + offset

End Function



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Anil K." wrote in message
...
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.












  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default Can a function return two values?

ByRef is the default, so all 3 arguments (var, station & offset) are passed
by reference.

The only qualifier actually required is ByVal to switch off passing by
reference.

"Bob Phillips" wrote in message
...
Here is an example

Function GE()
Dim a As Long
Dim station As Long, offset As Long

station = 1
offset = 2
a = 3
Call ff(a, station, offset)

MsgBox station & ", " & offset
GE = elevation(station, offset)
MsgBox GE

End Function

Function ff(var As Long, ByRef station As Long, ByRef offset As Long)

station = var + 1
offset = var ^ 2 + 1

End Function

Function elevation(station As Long, offset As Long)

elevation = station + offset

End Function



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Anil K." wrote in message
...
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.














  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default Can a function return two values?

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." wrote in message
...
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.














  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Can a function return two values?

Correct, b ut declaring it Byref makes it clearer.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Paul Lautman" wrote in message
...
ByRef is the default, so all 3 arguments (var, station & offset) are

passed
by reference.

The only qualifier actually required is ByVal to switch off passing by
reference.

"Bob Phillips" wrote in message
...
Here is an example

Function GE()
Dim a As Long
Dim station As Long, offset As Long

station = 1
offset = 2
a = 3
Call ff(a, station, offset)

MsgBox station & ", " & offset
GE = elevation(station, offset)
MsgBox GE

End Function

Function ff(var As Long, ByRef station As Long, ByRef offset As Long)

station = var + 1
offset = var ^ 2 + 1

End Function

Function elevation(station As Long, offset As Long)

elevation = station + offset

End Function



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Anil K." wrote in message
...
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.
















Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Address function to return values from min row Laury Excel Discussion (Misc queries) 3 October 4th 07 07:59 PM
IF Function with multiple return values jerminski73 Excel Worksheet Functions 6 April 28th 07 12:16 AM
A Function to Return Top 5 Values Only Sean Excel Worksheet Functions 4 December 29th 06 12:34 PM
How can I use the vlookup function to return a sum of the values? Chaandni Excel Discussion (Misc queries) 4 November 7th 05 03:05 PM
vlookup function return all values j2thea Excel Worksheet Functions 20 November 2nd 05 10:32 PM


All times are GMT +1. The time now is 05:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"