Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > Beginning VB 6
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 28th, 2007, 10:45 AM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default if statements to test for third Wed 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

 
Old March 30th, 2007, 10:03 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

There would be a span of days-of-the-month for a Wednesday that is the 3rd Wednesday of the month. 15 — 21, I believe. If that is the right range, then it would be the same for any day of the week. So if the dat is >= 15 and <= 21 and the weedkday is that which represents Wednesday, then you are within your span.

If you think about it, if 1 is the date of the first Wednesday, then 14 will be the date of the tuesday before the 3rd Wednesday.
If 1 is the date of the first Thursday, the first Wednesday will be 6. the Wednesdays will be 7, 14, and 21. 15 is 1 higher, dodging therefore the 2nd Wednesday.
 
Old April 17th, 2007, 03:44 PM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting month name to month number kalyanykk SQL Server 2005 7 August 19th, 2008 10:37 PM
month calendar bschleusner C# 2005 0 April 13th, 2007 09:46 PM
query Current Month, Month+1, Month+2, Month+3 anterior Access 2 September 24th, 2006 08:25 PM
get current month cathiec SQL Language 2 February 23rd, 2006 09:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.