Reputation: 19
I am almost done this snippet of code, which should allow me to calculate the number of tuesdays, thursdays, saturdays and sundays in 2 date ranges. The line "skips = ModWeekdays(NotificationDate, OrderDate, PlacementDate, ReleaseDate)" is highlighted and the error box says error '28', out of stack space. Can someone help me out here?
'//////This is for Valley Estimate of Demurrage Days/////////////
Public Function ModWeekdays(ByRef NotificationDate As Date, ByRef OrderDate As Date, ByRef PlacementDate As Date, ByRef ReleaseDate As Date) As Integer
Dim skips As Integer
Dim WeekendDays As Integer
Dim WeekendDays2 As Integer
'skips = 0
WeekendDays = 0
WeekendDays2 = 0
Do While NotificationDate <= OrderDate
If DatePart("w", NotificationDate) = 0 Then
WeekendDays = WeekendDays + 1
ElseIf DatePart("w", NotificationDate) = 2 Then
WeekendDays = WeekendDays + 1
ElseIf DatePart("w", NotificationDate) = 4 Then
WeekendDays = WeekendDays + 1
ElseIf DatePart("w", NotificationDate) = 6 Then
WeekendDays = WeekendDays + 1
End If
NotificationDate = DateAdd("d", 1, NotificationDate)
Loop
Do While PlacementDate <= ReleaseDate
If DatePart("w", PlacementDate) = 0 Then
WeekendDays2 = WeekendDays2 + 1
ElseIf DatePart("w", PlacementDate) = 2 Then
WeekendDays2 = WeekendDays2 + 1
ElseIf DatePart("w", PlacementDate) = 4 Then
WeekendDays2 = WeekendDays2 + 1
ElseIf DatePart("w", PlacementDate) = 6 Then
WeekendDays2 = WeekendDays2 + 1
End If
PlacementDate = PlacementDate + 1
Loop
skips = WeekendDays + WeekendDays2
skips = ModWeekdays(NotificationDate, OrderDate, PlacementDate, ReleaseDate)
End Function
Upvotes: 0
Views: 512
Reputation: 2335
I'm confused. At what point does this recursive function actually end? Within it you have the following:
skips = ModWeekdays(NotificationDate, OrderDate, PlacementDate, ReleaseDate)
I can't work out for the life of me at what point it will stop doing this (I suspect never). I think what is happening is you are constantly calling the function over and over again and eventually you just run out of space, hence your error.
Upvotes: 3