Here is the code I'm working on. The user should be able to type in a number and then after clicking the button, list (in a listbox) of all the prime numbers leading up to the number (including the number if it's prime)

MY ERROR/PROBLEM: When i input a number value, it get a list of nothing...and it(the form) locks up. I know it works up to the "msgbox" code (i've tested for 1). Please help where you can and thank you for your time.

--------
Public Class frmPrime

Private Sub btnCompute_Click(....) Handles btnCompute.Click
Dim prim As Integer
'im test As Integer 'to test each number up to prim
Dim imPrime As Boolean = False
prim = CInt(txtNum.Text)
test = prim
'loop while prim is greater than 1 and not equal to prim

'As long as the number is greater than 1
If prim = 1 Then
imPrime = False
MessageBox.Show("Enter a number greater than one please")
Else
Do While prim >= 2
For i As Integer = 2 To prim
If prim Mod i = 0 Then
imPrime = False
Exit For
Else
imPrime = True
lstPrime.Items.Add(prim)
End If
Next
Loop
End If
'If imPrime = True Then
'lstPrime.Items.Add(prim)
'End If

End Sub
End Class

you need to add a do event to your code.

oh...wow...thank you. It works...

This article has been dead for over six months. Start a new discussion instead.