Originally Posted by
davegri
Code in Post#8 is a bit misleading.
Here's a more accurate version with a couple of comments
the comments in the revised code did clarify one point for me. I've commented the original from post 8, to demonstrate what I think I know and highlight the fuzz.
thanks in advance for sharing your knowledge and helping me learn.
Code:
'nameTheFunction(variable for a necessary value) function result type
Public Function fcnIsWeekEnd(dDate As Date) As Boolean
'state the function using the necessary variable
'if the dDate variable supplied is = to saturday or sunday, then return true, else false
fcnIsWeekEnd = IIf(Weekday([dDate], vbSunday) = vbSaturday Or Weekday([dDate], vbSunday) = vbSunday, True, False)
End Function
' name the subroutine that will call the function
Public Sub CheckForWeekend()
'declare variable to capture the value that the function uses
'testdate = dDate
Dim testdate As Date
'evalute the expression and assign the value to testdate variable
'where is the date coming from in order to evaluate and populate the message box?
If fcnIsWeekEnd(Date - 1) Then
MsgBox Date & " is weekend"
Else
MsgBox Date & " is not a weeekend"
End If
'testdate variable assigned a new value, that is converted into Date data type
'the value of the variable testdate is hard coded here.
testdate = CDate("8/1/2021")
'the function evaluates the value of testdate and displays the message
'but why does this have to be coded two times?
If fcnIsWeekEnd(testdate) Then
MsgBox testdate & " is weekend"
Else
MsgBox testdate & " is not a weeekend"
End If
End Sub