I need to be able to automatically calculate the next meeting date for an organization (monthly meetings) that has different groups that meet on specified dates such as the 3rd Monday or the 1st Tuesday. Is there an easy way to do this or a does MBS or Einhugur have this feature?
Edit: As you may know, I’m learning Xojo, so I took your information to see if I can find a solution.
For 3rd Monday of the Month:
[code]Listbox1.DeleteAllRows
For i As Integer = 1 To 12
Dim d As New date(2018, i, 1)
Dim dw As Integer = d.dayofweek
Select Case dw
Case 1
Listbox1.AddRow(Str(i),“16”)
Case 2
Listbox1.AddRow(Str(i),“15”)
Case 3
Listbox1.AddRow(Str(i),“21”)
Case 4
Listbox1.AddRow(Str(i),“20”)
Case 5
Listbox1.AddRow(Str(i),“19”)
Case 6
Listbox1.AddRow(Str(i),“18”)
Case 7
Listbox1.AddRow(Str(i),“17”)
End Select
Next
[/code]
For the 1st Tuesday:
[code]Listbox1.DeleteAllRows
For i As Integer = 1 To 12
Dim d As New date(2018, i, 1)
Dim dw As Integer = d.dayofweek
Select Case dw
Case 1
Listbox1.AddRow(Str(i),“3”)
Case 2
Listbox1.AddRow(Str(i),“2”)
Case 3
Listbox1.AddRow(Str(i),“1”)
Case 4
Listbox1.AddRow(Str(i),“7”)
Case 5
Listbox1.AddRow(Str(i),“6”)
Case 6
Listbox1.AddRow(Str(i),“5”)
Case 7
Listbox1.AddRow(Str(i),“4”)
End Select
Next
[/code]
Public Function Nth_WeekDay_of_Month(byref dt as date,dow as integer,num as integer) as boolean
If dow<1 Or dow>7 Or num<1 Or num>5 Then Return False// illegal request
// find the 1st of the month supplied
dt.day=1
// move to the 1
While dt.DayOfWeek<>dow // 1=Sun 7=Sat
dt.day=dt.day+1
Wend
// date is now the 1st "dow" of the month
If num>1 Then dt.day=dt.day+(num-1)*7
Return True
End Function
this should find the Nth DOW of any month
dim dt as new date
dim x as boolean
x=Nth_WeekDay_of_Month(dt,2,3) // find 3rd Monday, returned in DT, x=false if bad data
Changing my code to use Dave’s function:
For 3rd Monday
For i As Integer = 1 To 12
Dim dt As New date(2018, i, 1)
Dim x As Boolean
x=Nth_WeekDay_of_Month(dt,2,3)
if x then
listbox1.AddRow(Str(i), Str(dt.day))
Else
MsgBox "Check your input"
Exit
End If
Next