Skip to content

Instantly share code, notes, and snippets.

@warham2012
Created October 26, 2013 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warham2012/7163809 to your computer and use it in GitHub Desktop.
Save warham2012/7163809 to your computer and use it in GitHub Desktop.
Prime Number Application
Dim numValue As Integer = 0
Dim maxNumValue As Integer = 0
Private Sub btnPrime_Click(sender As Object, e As EventArgs) Handles btnPrime.Click
lstPrimeNumbers.Items.Clear()
numValue += 1
maxNumValue = txtMaxNumber.Text
For Me.numValue = 0 To maxNumValue
isNumberPrime()
Next
End Sub
Private Sub isNumberPrime()
Dim isPrime As Boolean = False
Dim a, c As Integer
a = numValue
c = 0
For i = (a - 1) To 2 Step -1
If a Mod i = 0 Then
c += 1
End If
Next i
If c = 0 Then
isPrime = True
End If
If isPrime = True Then
lstPrimeNumbers.Items.Add(numValue)
End If
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment