Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning Multiple values from a Function 2

Status
Not open for further replies.

deharris2003

Programmer
Jul 1, 2003
41
US
OK I know that it is considered bad form to return more than one value form a function but here goes... I have two functions that seems to be redundant. My goal is to calculate the actual fiscal year start and stop dates. here is my current functions

<%
Public Function FiscalStart()

If Date() < &quot;10/01/&quot; & Year(Date()) Then
FiscalStart = CDate(&quot;10/01/&quot; & Year(Date())-1)
Else
FiscalStart = CDate(&quot;10/01/&quot; & Year(Date()))
End IF

End Function

Public Function FiscalEnd()

IF Date() < &quot;10/01/&quot; & Year(Date()) Then
FiscalEnd = CDate(&quot;09/30/&quot; & Year(Date())-1)
Else
FiscalEnd = CDate(&quot;09/30/&quot; & Year(Date()))
End If

End Function
%>

Can this be done in one function or is there a better way to calculate the dates. Any help and sugestions are much appreciated

 
you could return the dates as an array, or return them as a string with a delimiter, like &quot;10/1/2003|10/1/2004&quot; and then split them yourself



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
One more possibility would be to create a small object to hold the values. In the case of two dates I would probably go with the delimiter, but if you find yourself needing to pass back more values it might be cleaner to create a small class to hold the values and pass that back:
Code:
Class DateGroup
   Public fiscal_date
   Public end_date
   Public something_else
End Class

This method is more geared towards occasionas where you might not be setting one of the variables or you have several you want to return. This way you can create the object in your function, set only the variables you need, and pass it back. Once you pass it back the code can use it directly without needing to parse, etc.

Anyways, just a quick coment for future multiple variable passing :)

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
minilogo.gif alt=tiernok.com
The never-completed website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top