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")
Do While prim >= 2
For i As Integer = 2 To prim
If prim Mod i = 0 Then
imPrime = False
Exit For
imPrime = True
End If
End If
'If imPrime = True Then
'End If

End Sub
End Class

Recommended Answers

All 2 Replies

you need to add a do event to your code.

you need to add a do event to your code. you. It works...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.