Public Class frmDays

  Private Sub btnDetermine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDetermine.Click
    Dim month As Integer = CInt(mtbMonth.Text)
    Dim yr As Integer = CInt(mtbYear.Text)
    Dim d1, d2 As Date
    Dim numberOfDays As Integer
    Select Case month
      Case 9, 4, 6, 11   'September, April, June, and November
        numberOfDays = 30
      Case 2    'February
        d1 = CDate("1/1/" & yr)
        d2 = d1.AddYears(1)
        If DateDiff(DateInterval.Day, d1, d2) = 366 Then
          numberOfDays = 29
        Else
          numberOfDays = 28
        End If
      Case Else    'all the rest
        numberOfDays = 31
    End Select
    txtOutput.Text = month & "/" & yr & "  has " &
        numberOfDays & " days."
  End Sub

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Dim month As Integer = CInt(mtbMonth.Text)
    Dim yr As Integer = CInt(mtbYear.Text)
    Dim d1, d2 As Date
    d1 = CDate(month & "/" & 1 & "/" & yr)
    d2 = d1.AddMonths(1)
    Dim numberofdays = DateDiff(DateInterval.Day, d1, d2)
    txtOutput.Text = CStr(numberofdays)
  End Sub
End Class
