|
-
Mar 28th, 2007, 10:45 AM
#1
Thread Starter
New Member
if statements to test for third Wed of the month & third Thurs. of the month
hello,
what would be the VB6 code for an if statement that would check for if it's the third wednesday of the month and execute some code based on that. Also would would be the similar code for if it's the third thursday of the month?
thanks in advance,
david
-
Mar 28th, 2007, 11:10 AM
#2
Addicted Member
Re: if statements to test for third Wed of the month & third Thurs. of the month
The third wednesday will be the wednesday between the 15th and 21st (inclusive). the code is similar for the third thursday with the numbers being the 16th to the 22nd
so the vb code would look something like
vbcode Code:
If ((Day = wednesday) + (daynumber >= 15) + (daynumber <= 21)) Then
'code here
end if
I'm not sure how you are storing the day of the week and the day number but there is the basic logic for it.
-
Mar 28th, 2007, 11:30 AM
#3
Re: if statements to test for third Wed of the month & third Thurs. of the month
Here is code to get the 3rd Wednesday. It is based on some code by member CVMichael.
vb Code:
Private Sub Form_Load()
MsgBox ThirdWednesday(2007, 3) ' Year and month
End Sub
Private Function ThirdWednesday(ByVal Y As Integer, ByVal M As Integer) As Date
Dim TheDate As Date
TheDate = DateSerial(Y, M, 1)
TheDate = DateAdd("d", -Weekday(TheDate) + 25, TheDate)
ThirdWednesday = TheDate
End Function
-
Mar 28th, 2007, 04:33 PM
#4
Re: if statements to test for third Wed of the month & third Thurs. of the month
 Originally Posted by TBeck
The third wednesday will be the wednesday between the 15th and 21st (inclusive). the code is similar for the third thursday with the numbers being the 16th to the 22nd.
Regardless of the day of the week, the third occurance of any given day of the week will be between the 15th and 21st.
vb Code:
If Weekday(Date) = vbWednesday And Day(Date) >= 15 And Day(Date) <= 21 Then
MsgBox "Today is the third wednesday of the month"
End If
-
Mar 28th, 2007, 04:58 PM
#5
Re: if statements to test for third Wed of the month & third Thurs. of the month
Something else to note, the third occurance of any given day of week could also happen BEFORE the third occurrance of the day before -- IE, the third Thursday could happen before the third Wednesday.
-tg
-
Apr 17th, 2007, 03:42 PM
#6
Thread Starter
New Member
Re: if statements to test for third Wed of the month & third Thurs. of the month
thanks for everyone's input. With your help, I came up with this test code that worked well as I changed the pc's calendar to the third wed, third thurs and some other days.
Code:
If Weekday(Date) = vbWednesday And Day(Date) >= 15 And Day(Date) <= 21 Then
MsgBox "Today is the third Wednesday of the month"
Else
If Weekday(Date) = vbThursday And Day(Date) >= 15 And Day(Date) <= 21 Then
MsgBox "Today is the third Thursday of the month"
Else
MsgBox "today is the " & Weekday(Date) & " / " & Day(Date) & " day of " & Month(Date) & " " & Year(Date)
End If
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|