Colleagues,
Two ComboBoxes, "From" and "To", both have months numbers listed (1...12), let the User to determine the period.
For the sake of verification, I check if the month From is greater than the month To. Here's the code:
The problem I have is that neither of these two CBOs changes the selected item!
Let's say, User selected month From = 5 and - mistakenly - month To = 2; when the line toMonthFromCBO.SelectedItem() = lnMonthTo is executed, toMonthFromCBO.SelectedItem() still shows 5, not 2.
What am I doing wrong?
Regards,
Ilya
Two ComboBoxes, "From" and "To", both have months numbers listed (1...12), let the User to determine the period.
For the sake of verification, I check if the month From is greater than the month To. Here's the code:
Code:
'====================================================================================================================================
Private Sub Compare_Months_From_To(toMonthFromCBO As ComboBox, toMonthToCBO As ComboBox)
'====================================================================================================================================
' Purpose : Validates User's selected entry into the MonthTo ComboBox on this Form.
' Description : Checks if the value selected in the corresponding From month is greater than the value in this ComboBox. If it is -
' warns the User and offers to reverse these selections; if User agrees - does so; if User refuses - makes the same
' selection as in the corresponding From ComboBox.
' Side effects : Shan't be any.
' Notes : 1. Company-, application- and form-specific.
' 2. No "parameters" verification, presumed valid (the calling proc must perform all the checks).
' 3. Complies with .NET Framework ver. 1.1 and higher.
' Author : Ilya I. Rabyy
' Revisions : 2021-08-31 by Ilya – started 1st draft.
'====================================================================================================================================
Dim lnAns As Int16 = 0, lnMonthFrom As Int16 = Val(toMonthFromCBO.Text), lnMonthTo As Int16 = Val(toMonthToCBO.Text)
Dim lcMsg As String = "The value for the Month To you have entered cannot be less than that selected for Month From!" & vbCrLf & _
"Do you want to switch these values to put them in reverse?" & vbCrLf & "If not, then the month number in" & _
" Month To box will be made equal to the one in Month From box (making it coverage for 1 month)."
If lnMonthFrom > lnMonthTo Then 'Offer to User to switch values
lnAns = MsgBox(lcMsg, vbYesNo + vbQuestion, "WARNING: Invalid User's Data Entry")
If lnAns = vbYes Then
toMonthFromCBO.SelectedItem() = lnMonthTo
toMonthToCBO.SelectedItem() = lnMonthFrom
Else
toMonthToCBO.SelectedItem() = lnMonthFrom
End If
End If 'lnMonthFrom > lnMonthTo Then 'Offer to User to switch values
End Sub
'====================================================================================================================================
The problem I have is that neither of these two CBOs changes the selected item!
Let's say, User selected month From = 5 and - mistakenly - month To = 2; when the line toMonthFromCBO.SelectedItem() = lnMonthTo is executed, toMonthFromCBO.SelectedItem() still shows 5, not 2.
What am I doing wrong?
Regards,
Ilya