Hi,
I'v just started learning VB. i need help with a program that allows the user to enter a month and a number of years. (e.g March and 10 years)
The program then displays all the months of the year from the entered month in a loop that runs as many times as the number of years.(e.g March April May.....December January February March....)
Thanks in advance.

See if this helps.
2 TextBoxes, 1 Button, 1 ListBox

Public Class Form1
    '// lowercase for testing against lowercase Text from the TextBox.
    Private myMonths() As String = {"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"}

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = "March" : TextBox2.Text = "10"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ListBox1.Items.Clear() '// clear for new input.
        Dim iMonthNumber As Integer = 0
        '// get the starting month by #.
        For i As Integer = 0 To myMonths.Length - 1 '// loop thru all arrays in the myMonths String Array.
            '// use .ToLower since user can type a "month" as "MonTh" and it will still get recognized.
            If TextBox1.Text.ToLower = myMonths(i) Then '// check if TextBox.Text equals the month in your myMonths String Array.
                iMonthNumber = i  '// add the month number that coresponds to the month in your myMonths String Array.
                Exit For '// Exit the loop since month was located.
            End If
        Next
        '// add months.
        For i As Integer = 1 To CInt(TextBox2.Text) '// loop from 1 to as many years.
            For x As Integer = 0 To myMonths.Length - 1 '// loop thru all months.
                '// if first item in ListBox, add the found month. vbProperCase to Capitalize first letter.
                ListBox1.Items.Add(StrConv(myMonths(iMonthNumber), vbProperCase))
                iMonthNumber += 1 '// increase to add the next month.
                If iMonthNumber = myMonths.Length Then iMonthNumber = 0 '// if monthNumber ='s the length of your myMonths Array, reset it back to 0.
            Next
            '// add the last month to the list.
            If i = CInt(TextBox2.Text) Then ListBox1.Items.Add(StrConv(myMonths(iMonthNumber), vbProperCase))
        Next
        MsgBox("Total Months added: " & ListBox1.Items.Count.ToString, MsgBoxStyle.Information)
    End Sub
End Class
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.