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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing arguments to function returning array

Status
Not open for further replies.

daybase

Technical User
Dec 13, 2002
115
GB
Way out of my depth here so all help gratefully received. I have an application that requires multiple calculations on any particular record and my function takes details from the open form, calculates and returns the values in an array - works great. Problem I have now is that I would like to re-use the function and rather than take values from the form I would like to pass arguments to the function. Is it possible? If so how as any argument is interpreted as a value returned from the array?

Public Function thruDUE()
Dim vEarly As Date
Dim vLate As Date
Dim vCurrent As Currency
Dim vMin As Currency
Dim vMax As Currency
Dim vArrearsbf As Currency
Dim vArrearscf
Dim vQdue
Dim vTotdue
Dim vBalance
Dim vInfo

if IsOpen("Main Property") then
vEarly=month([forms]![mainproperty]![vDate1])
vLate=year([forms]![mainproperty]![vDate1])
vMin=[forms]![mainproperty]![vDue1]/1.75
vMax=[forms]![mainproperty]![vDue2]*1.75
vArrearsbf=[forms]![mainproperty]![vArr1]+[forms]![mainproperty]![varr2]
vQdue=[forms]![mainproperty]![vDue1]+[forms]![mainproperty]![vDue2]
vTotdue=vArrearsbf+vQdue
vBalance=vTotdue-[forms]![mainproperty]![vPaid]
end if

' Note - can we replace forms data with arguments?


vInfo = Array(vMin, vMax, vEarly, vLate, vCurrent, vArrearsbf, vQdue, vTotdue, vBalance)
thruDUE = vInfo

End Function
 

Try:
Code:
Public Function thruDUE(vEarly As Date, vLate As Date, _
    vCurrent As Currency, vMin As Currency, _
    vMax As Currency, vArrearsbf As Currency, _
    vArrearscf [blue]As ???[/blue], vQdue As [blue]???[/blue], _
    vTotdue As [blue]???[blue], vBalance As [blue]???[/blue])(0 To 8) As String

thruDUE = Array(vMin, vMax, vEarly, vLate, vCurrent, vArrearsbf, vQdue, vTotdue, vBalance)

End Function
Of course if your Function will return a String array, you need to Convert vMin, vMax, etc to String.

Have fun.

---- Andy
 
Something like this ?
Code:
Public Function thruDUE(vDate1 As Date, vDue1 As Currency, vDue2 As Currency, vArr1 As Currency, vArr2 As Currency, vPaid)
Dim vEarly As Date
Dim vLate As Date
Dim vCurrent As Currency
Dim vMin As Currency
Dim vMax As Currency
Dim vArrearsbf As Currency
Dim vQdue
Dim vTotdue
Dim vBalance
Dim vInfo

vEarly = vDate1
vLate = Year(vDate1)
vMin = vDue1 / 1.75
vMax = vDue2 * 1.75
vArrearsbf = vArr1 + vArr2
vQdue = vDue1 + vDue2
vTotdue = vArrearsbf + vQdue
vBalance = vTotdue - vPaid
' Note - vCurrent = ???
vInfo = Array(vMin, vMax, vEarly, vLate, vCurrent, vArrearsbf, vQdue, vTotdue, vBalance)
thruDUE = vInfo
End Function

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you for the amazingly quick response as usual.

PHV - my approach was the same as yours but I then have the problem of calling the function

thruDue(date1,due1,due2.... etc etc

but I get the error message "Argument not optional" which I am assuming is because something like thruDUE(1)would be extracting info from the array.
 
Probably a lot easier to work with a user defined class or a user defined type
Code:
Type thruDueInfo
  vEarly As Date
  vLate As Date
  vCurrent As Currency
  vMin As Currency
  vMax As Currency
  vArrearsbf As Currency
  vQdue As Currency
  vTotdue As Currency
  vBalance As Currency
End Type
  
  
Public Function getThruDUE(vDate1 As Date, vDue1 As Currency, vDue2 As Currency, vArr1 As Currency, vArr2 As Currency, vPaid) As thruDueInfo
  Dim td As thruDueInfo
  td.vEarly = vDate1
  td.vLate = Year(vDate1)
  td.vMin = vDue1 / 1.75
  td.vMax = vDue2 * 1.75
  td.vArrearsbf = vArr1 + vArr2
  td.vQdue = vDue1 + vDue2
  td.vTotdue = td.vArrearsbf + td.vQdue
  td.vBalance = td.vTotdue - vPaid
  getThruDUE = td
End Function

Public Sub testthrudue()
  Dim td As thruDueInfo
  td = getThruDUE(#1/1/2007#, 1, 2, 3, 4, 5)
  Debug.Print td.vEarly & " " & td.vLate
End Sub
 
Problem solved - many thanks to you all
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top