Zebra0.com

Learn to Program Step-by-Step

Seasons

Determing season from month

Seasons

We use list box to select month then show season

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) _
	  Handles MyBase.Load
        Me.CboMonths.Items.Add("January")
        Me.CboMonths.Items.Add("Feb")
        Me.CboMonths.Items.Add("March")
        Me.CboMonths.Items.Add("April")
        Me.CboMonths.Items.Add("May")
        Me.CboMonths.Items.Add("June")
        Me.CboMonths.Items.Add("July")
        Me.CboMonths.Items.Add("August")
        Me.CboMonths.Items.Add("Sept")
        Me.CboMonths.Items.Add("Oct")
        Me.CboMonths.Items.Add("Nov")
        Me.CboMonths.Items.Add("Dec")
        Me.CboMonths.SelectedIndex = 0
    End Sub

    Private Sub CboMonths_SelectedIndexChanged(sender As Object, e As EventArgs) _
	  Handles CboMonths.SelectedIndexChanged
        Dim month As Integer = CboMonths.SelectedIndex + 1
        Dim season As String = ""
        Select Case month
            Case 12, 1, 2
                season = "Winter"
            Case 3 To 5
                season = "Spring"
            Case 6 To 8
                season = "Summer"
            Case Else
                season = "Autumn"
        End Select
        showSeason(season)
    End Sub
    Private Sub showSeason(Season As String)
        Me.Text = "The season is " & Season
    End Sub
End Class


Download Source file
Lesson
Last modified: January 30 2025 14:19:35.