我几乎完成了这段代码,它应该允许我计算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
为什么你总是再次调用你的函数? – SLaks
,因为我想导出要访问的函数的值。我想我会使用变量“跳过”来做这个 – NavyNuke
如果你需要从函数返回值,那么赋值语句是向后的。尝试:'ModWeekdays =跳过'而不是'skips = ModWeekdays(NotificationDate,...') –