Hello I'm Writing a program that computes the number of ‘1’ bits in a given 32-bit integer number.
I did a program that works fine with the first number i put. but when i try another number, it misses up!. then i have to run the program again. I think i need to reset count and moon at the begining of the button so the variables get reset each time the button is pushed. but I don't know how to do that!
this what i have so far
Code:Public Class Form1 Dim count As Integer Dim moon As Integer = 2 ^ 31 - 1 Dim i As Integer Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged i = TextBox1.Text End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x As Integer For x = 0 To 31 If i >= moon Then count = count + 1 i = i - moon End If moon = moon / 2 Next MsgBox(count) End Sub End Class
thank you,




Reply With Quote