Reputation: 27
My program needs to write all EVEN numbers equal to or lower than the number I enter.
This is what have so far. I don't understand why it doesn't work.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim nombre As Integer
Dim valca As Integer
number = Convert.ToInt16(txtnombre.Text)
While number > 0
number -= 1
valca = number Mod 2
If valca = 0 Then
lblreponse.Text += CStr(number) + " "
Else
lblreponse.Text = " "
End If
End While
End Sub
End Class
Upvotes: 0
Views: 39
Reputation: 57388
If valca = 0 Then
lblreponse.Text += CStr(number) + " "
Else
lblreponse.Text = " "
End If
If the number is odd, lblreponse.Text is overwritten with a space. All previous data is lost.
What you want to do is probably just
If valca = 0 Then
lblreponse.Text += CStr(number) + " "
End If
Actually... once you get an even number, why don't continue subtracting two instead of one?
Upvotes: 1