堆栈空间错误

时间:2014-02-18 15:39:50

标签: vba ms-access

我差不多完成了这段代码,这可以让我计算2个日期范围内的星期二,星期四,星期六和星期日的数量。行“skips = ModWeekdays(NotificationDate,OrderDate,PlacementDate,ReleaseDate)”突出显示,错误框显示错误“28”,堆栈空间不足。有人可以帮助我吗?

'//////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

1 个答案:

答案 0 :(得分:3)

我很困惑。这个递归函数到底在什么时候结束?在其中你有以下内容:

skips = ModWeekdays(NotificationDate, OrderDate, PlacementDate, ReleaseDate)

我不能为我的生活做好准备,在什么时候它会停止这样做(我怀疑从来没有)。我认为正在发生的事情是你不断地一遍又一遍地调用这个函数,最终你的空间不足,因此你的错误。

相关问题