Hi,

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

thanks

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

compare with today year and month. use Now.Year or Now.Month

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
commented: Helping me +1

thanks guys it worked :)

you're welcome.
don't forget to mark this thread solved :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.