Try this:
vb Code:
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Isprime As Integer Dim str As String Dim m As Integer Dim n As Integer Dim TestLimit As String Dim TestPrime As String Dim TestNum As String str = "" m = InputBox("Enter Upper limit") n = InputBox("Enter lower limit") If (n > 50) Then MsgBox("outside range") Exit Sub End If ' ' Eliminate even numbers If TestPrime Mod 2 = 0 Then Exit Sub ' Loop through ODD numbers starting with 3 TestNum = 3 TestLimit = TestPrime Do While TestLimit > TestNum for x= TestNum to TestLimit step 2 If TestPrime Mod TestNum = 0 Then ' Uncomment this if you really want to know ' MsgBox "Divisible by " & TestNum Exit Sub End If ' There's logic to this. Think about it. TestLimit = TestPrime \ TestNum ' Remember, we only bother to check odd numbers TestNum = TestNum + 2 if prime then list.additem x next x Loop ' If we made it through the loop, the number is a prime. Isprime = True End Sub
I have requested the thread moved since you are using vb.net not vb6. Something such as that although, I haven't tested it so I can't be sure.




Reply With Quote