我有一个函数可以找到下一个星期一的日期。当没有传递可选的日期参数时,它会默认为零。我想我已经包含了解释问题的评论
Function NextMondayFromADateOrToday(Optional StartDate As Date) As Date
' objective: if date param not supplied should set StartDate to today
' ??? Problem: with no arg provided StartDate is zero = date value of 1/1/1900
' ??? how to add default to optional paramater of date type?
' ??? or, how to check if an arg was provided if the parameter is date type?
If Not (IsDate(StartDate)) Then StartDate = Date
Select Case Weekday(StartDate)
Case 1: NextMondayFromADateOrToday = StartDate + 1
Case 2: NextMondayFromADateOrToday = StartDate + 0
Case 3: NextMondayFromADateOrToday = StartDate + 6
Case 4: NextMondayFromADateOrToday = StartDate + 5
Case 5: NextMondayFromADateOrToday = StartDate + 4
Case 6: NextMondayFromADateOrToday = StartDate + 3
Case 7: NextMondayFromADateOrToday = StartDate + 2
End Select
End Function