There are three combo boxes in my program used to input the date (cboMonth, cboDay, and cboYear).
Problem: When the value "2" (February) is selected on cboMonth, the values on cboDay go up to 31 even though it should reach up to 28 (or 29 when cboYear's value is a leap year). Same happens when the values for April, June, September, and November in cboMonth.
Code:
Private Function DateParse()
'refresh combobox values
cboMonth.Clear
cboDay.Clear
cboYear.Clear
'setting default combobox values
monthCount = 1
dayCount = 1
yearCount = 2012
If cboMonth.ListIndex = 1 Then
If cboYear.ListIndex Mod 4 = 0 Then
dayMax = 29
Else
dayMax = 28
End If
ElseIf cboMonth.ListIndex = 3 Or cboMonth.ListIndex = 5 Or cboMonth.ListIndex = 8 Or cboMonth.ListIndex = 10 Then
dayMax = 30
Else
dayMax = 31
End If
monthCount = 1
Do While monthCount <= 12
cboMonth.AddItem monthCount
cboMonth.ItemData(cboMonth.NewIndex) = monthCount
monthCount = monthCount + 1
Loop
Do While dayCount <= dayMax
cboDay.AddItem dayCount
cboDay.ItemData(cboDay.NewIndex) = dayCount
dayCount = dayCount + 1
Loop
Do While yearCount <= 2099
cboYear.AddItem yearCount
cboYear.ItemData(cboYear.NewIndex) = yearCount
yearCount = yearCount + 1
Loop
End Function