Private Sub displayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles displayButton.Click ' displays the odd and even numbers between two integers Dim intNum1 As Integer Dim intNum2 As Integer Dim intOdd As Integer Dim intEven As Integer Integer.TryParse(number1TextBox.Text, intNum1) Integer.TryParse(number2TextBox.Text, intNum2) For counter As Integer = intNum1 To intNum2 If (intNum1) Mod 2 <> 0 Then oddLabel.Text = intNum1.ToString & vbNewLine intNum1 = intNum1 + 1 Else evenLabel.Text = intNum1.ToString & vbNewLine intNum1 = intNum1 + 1 End If Next counter End Sub
I'm not exactly sure what this code is doing. When I put 1 in the first number and 10 in the second number, the odd label only shows 9 and the even label only shows 10. Another example is when I put 2 and 15, the odd label comes out as 15 and the even label is 14. I'm very new to VB and programming in general and have just started getting into for...next loops and don't fully understand what the counter is or how the loop is supposed to work. I guess I'm having 2 problems. One is that I don't know how to make the program find the right numbers(my logic is off? or how I set up the loop isn't right?) and the other is the labels are showing only 1 number each instead of all the numbers in between on their own line. Thanks a lot to anyone who can help me out.