i have two textboxes one for month(2digits) and one for year(4digits).

i want to validate them so users cannot input dates in past. what would be a better way of doin this.

ps. it is for winforms


8 Years
Discussion Span
Last Post by Jx_Man

would it be easier to only let the user select a date instead of insert? maybe change the textboxes to comboboxes and in the form load event do something like this:

Dim y As Date
y = Date.Today
Dim i As Integer
        Dim x As Integer
        x = 0
        i = 0
        While (i < 20) 'display the next 20 years
            Me.cboYear.Items.Add(CInt(y.Year) + x)
            i = i + 1
            x = x + 1
        End While

do the same with the month.
then you can validate that it is a later date by referencing the date.month and date.year is greater then the cboYear.text and cbomonth.text?

just an option to consider

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Year.Text < Now.Year Then
            MsgBox("Cannot input past year")
        ElseIf Year.Text = Now.Year Then
            If Trim(Month.Text) < Now.Month Then
                MsgBox("Cannot input past month")
            End If
        End If
    End Sub
Votes + Comments
Helping me
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.