# Visual Basic > Visual Basic .NET >  set the max and min value of a NumericUpdown using code

## Tajaldeen

I have a comboBox that stored months of the year(Jan  Dec) and a NumericUpDown with maximum value of 100
I choose the month from comboBox and insert a number into NumericUpDown then press save button.
The issue is that when I choose (June or December) from the comboBox I want the maximum value of NumericUpdown to accept only 30 or less, down to zero , or at least gives a warning message that I should insert the right value which supposed to be 30 or less for June and Dec.



```
If ComboBox1.Text = "Jan" Or ComboBox1.Text = "Dec" Then

     End If
```

----------


## paulg4ije

Don't forget April and September. Why not use a DateTimePicker which takes care of all that for you? If you must use a NumericUpDown control just change the Maximum value:



```
        If ComboBox1.Text = "Apr" Or ComboBox1.Text = "Jun" Or ComboBox1.Text = "Sep" Or ComboBox1.Text = "Nov" Then
            NumericUpDown1.Maximum = 30
        Else
            NumericUpDown1.Maximum = 31
        End If
```

You still need to accommodate February and leap years, so the DateTimePicker is definitely the best way to go.

----------


## .paul.

In your ComboBox selectedindes_changed event, put



```
NumericUpDown1.Maximum = DateTime.DaysInMonth(Now.Year, ComboBox1.Text)
```

----------


## Tajaldeen

Tank you so much , that did the trick perfectly  :wave:

----------


## .paul.

> Tank you so much , that did the trick perfectly


Make sure you specify the correct year. February has 28 days this year, but 29 next year. Other than that, all of the other months have the same number of days every year

----------


## jmcilhinney

It's worth noting that DaysInMonth expects the month as a number from 1 to 12, so you probably ought to be using 'ComboBox1.SelectedIndex + 1'.

----------

