I have to create an application that will display all the odd and even numbers between the input values of number 1 and number 2. Display the output in a lstOdd and lstEven listbox. I have no clue I need help please?

Option Strict On
Option Explicit On

Public Class frmOddEven

    Dim number1, number2 As Integer

    Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click

        If (Not (IsNumeric(txtFirst.Text))) Or (Not (IsNumeric(txtSecond.Text))) Or (txtFirst.Text = Nothing) Or (txtSecond.Text = Nothing) Then
            MessageBox.Show("You must enter two numbers")
        Else
            number1 = CInt(txtFirst.Text)
            number2 = CInt(txtSecond.Text)
        End If
        If number1 = number2 Then
            MessageBox.Show("The numbers are equal")
            txtFirst.Clear()
            txtSecond.Clear()
        End If
        If number1 = 0 Or number2 = 0 Then
            MessageBox.Show("One of the numbers is zero")
            txtFirst.Clear()
            txtSecond.Clear()
        End If
        If number1 > number2 Then
            If number1 > 0 Then
                For i = 0 To number1
                    If ((i Mod number2) = 0) Then
                        lstOdd.Items.Add(i)
                    End If
                Next i
            ElseIf number1 < 0 Then
                For i = 0 To number1 Step -1
                    If ((i Mod number2) = 0) Then
                        lstOdd.Items.Add(i)
                    End If
                Next i
            End If
        End If
        If number2 > number1 Then
            If number2 > 0 Then
                For i = 0 To number2
                    If ((i Mod number1) = 0) Then
                        lstEven.Items.Add(i)
                    End If
                Next i
            End If
        ElseIf number2 < 0 Then
            For i = 0 To number2 Step -1
                If ((i Mod number1) = 0) Then
                    lstEven.Items.Add(i)
                End If
            Next i
        End If
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class

Not sure exactly, but i sort of see the code should read something like below. I haven't tested it but it looks like you are modding by i instead of 2, so try that
I haven't tested it

' from your line 26
            If number1 < number2 Then
                For i = number1 To number2
                    If ((i Mod 2) = 0) Then
                        lsteven.Items.Add(i)
                    else
                        lstOdd.Items.Add(i)
                    End If
                Next i
            ElseIf number1 > number2  Then
                For i = number2 To number1
                    If ((i Mod 2) = 0) Then
                        lsteven.Items.Add(i)
                    else
                        lstOdd.Items.Add(i)
                    End If
                Next i

            End If

I fixed it but now in my Even list box it repeats 2-24 even twice for some reason?

If number1 < number2 Then
            For i = number1 To number2
                If ((i Mod 2) = 0) Then
                    lstEven.Items.Add(i)
                Else
                    lstOdd.Items.Add(i)
                End If
            Next i
        ElseIf number1 > number2 Then
            For i = number2 To number1
                If ((i Mod 2) = 0) Then
                    lstEven.Items.Add(i)
                Else
                    lstOdd.Items.Add(i)
                End If
            Next i
        End If
        If number2 > number1 Then
            If number2 > 0 Then
                For i = 0 To number2
                    If ((i Mod number1) = 0) Then
                        lstEven.Items.Add(i)
                    Else
                        lstOdd.Items.Add(i)
                    End If
                Next i
            End If
        ElseIf number2 < 0 Then
            For i = 0 To number2 Step -1
                If ((i Mod number1) = 0) Then
                    lstEven.Items.Add(i)
                Else
                    lstOdd.Items.Add(i)
                End If
            Next i
        End If
    End Sub

Sorry, i meant for you to replace all that code. Lines 18-36 are unnecessary now, 1-17 should do everything you need.

ok thankx for all you help :)

Glad it worked :)

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.