R C Nesbit
2013-02-24 19:56:28 UTC
Problem:
Plant hire - the plant is hired by the day, but the hire
charge is by the week.
The hire charge is actually levied by the day, but only
Monday to Friday, i.e. if it is 100/week the charge is
20/day
Records hold an item of plant, the weekly rate, the date on
hire, and the date off-hire
The application looks at the record and the default date
off-hire is 1 day *before* the date on hire, unless the
hire is ended, when the off-hire date is set.
So the app must calculate the cost so far, or the cost from
on-hire to off-hire if the off-hire is changed to a data
after the on-hire date.
Problem is working out the cost for the on-hire days, only
accounting for Mon to Fri over days or weeks.
My solution is a function CalcHireCost, passed paramaters
on-hire(FDate), off-hire(TDate), and Rate
then I have:
iDays = DateDiff("d", FDate, TDate, vbMonday)
iSDay = 0
For i = 1 To iDays
If Weekday(DateAdd("d", i, FDate), vbMonday) < 6 Then
iSDay = iSDay + 1
End If
Next i
CalcHireCost = (iSDay * (Rate / 5))
Can anyone improve on this or see any logic-bombs in it?
Plant hire - the plant is hired by the day, but the hire
charge is by the week.
The hire charge is actually levied by the day, but only
Monday to Friday, i.e. if it is 100/week the charge is
20/day
Records hold an item of plant, the weekly rate, the date on
hire, and the date off-hire
The application looks at the record and the default date
off-hire is 1 day *before* the date on hire, unless the
hire is ended, when the off-hire date is set.
So the app must calculate the cost so far, or the cost from
on-hire to off-hire if the off-hire is changed to a data
after the on-hire date.
Problem is working out the cost for the on-hire days, only
accounting for Mon to Fri over days or weeks.
My solution is a function CalcHireCost, passed paramaters
on-hire(FDate), off-hire(TDate), and Rate
then I have:
iDays = DateDiff("d", FDate, TDate, vbMonday)
iSDay = 0
For i = 1 To iDays
If Weekday(DateAdd("d", i, FDate), vbMonday) < 6 Then
iSDay = iSDay + 1
End If
Next i
CalcHireCost = (iSDay * (Rate / 5))
Can anyone improve on this or see any logic-bombs in it?
--
Rob Pearson
Rob Pearson