-
I'm trying to use the DOW function to determine what day of the week a date is; when I run, however, I get an error that says "Compile error: sub or function not defined". Here's the code that I'm using:
intDayofweek=DOW(txtDate.text)
dtDayofweek is DIMed as an integer
Is there something wrong with the way I've coded it? Do I have to have some resource turned on in the project for this function to work?
-
<?>
Dim myDay as string
myDay = Format(now,"dddd")
msgbox myday
-
The reason why you get an error is because the function/sub "DOW" does not exist. But you can make a DOW function.
Try this:
Code:
Private Function DOW() As String
DOW = WeekDay(Date)
If DOW = 1 Then
DOW = "Sunday"
ElseIf DOW = 2 Then
DOW = "Monday"
ElseIf DOW = 3 Then
DOW = "Tuesday"
ElseIf DOW = 4 Then
DOW = "Wednesday"
ElseIf DOW = 5 Then
DOW = "Thursday"
ElseIf DOW = 6 Then
DOW = "Friday"
ElseIf DOW = 7 Then
DOW = "Saturday"
End If
End Function
Usage:
intDayofWeek = DOW()
MsgBox intDayofWeek
-
Thanks, folks!
Matthew, the function idea worked perfectly!!!! Thanks to both of you for taking the time to reply!
(BTW...the DOW thing came off of the MSDN library under DATE AND TIME FUNCTIONS - but I guess it wasn't for VB...)
-
it's probably an API Function
-
"DOW" is an old dBase (now FoxPro) function. As Matthew Gates indicates, the name of this function in VB is Weekday, which returns a value between 1 and 7 (1=Sunday, 7=Saturday). To get the name of the day of the week, in instead of doing the nested Ifs like Matthew, you can use the WeekdayName function:
Code:
Dim strDayName As String
strDayName = WeekdayName(Weekday(Now))