|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
sieve of erasothenes for #s 2-2000000000
Can someone help me out, I need vb.net code for a program that uses sieve of erasothenes for #s 2---2000000000. Must use an array type boolean to determine the primes and display them in text box on a seperate form. My code consists of this now:
Option Explicit Private Primes() As Long Private Function GetMax() As Long GetMax = CLng(Text1.Text) Exit Function GetMax = 0 Err.Raise -1, "GetMax", "Not a number" End Function Private Function IsPrime(ByVal Number As Long) IsPrime = False Dim I As Long For I = LBound(Primes) To UBound(Primes) DoEvents Call UpdateStatus(Number, Primes(I)) If (Number Mod Primes(I) = 0) Then Exit Function If (Primes(I) >= Sqr(Number)) Then Exit For Next IsPrime = True End Function Private Sub UpdateStatus(ByVal Number As Long, ByVal Prime As Long) If (Check1.Value = 0) Then Exit Sub StatusBar1.SimpleText = "Testing " & Number & _ " is divisible by Prime(" & Prime & ") = " & _ (Number Mod Prime = 0) End Sub Private Sub BuildPrimes(ByVal Max As Long) If (Max < 3) Then Exit Sub Dim I As Long For I = 2 To Max If (IsPrime(I)) Then ReDim Preserve Primes(UBound(Primes) + 1) As Long Primes(UBound(Primes)) = I End If Next End Sub Private Sub Command1_Click() On Error GoTo Handler Initialize Dim Value As Variant BuildPrimes (GetMax()) For Each Value In Primes List1.AddItem (Value) Next Exit Sub Handler: MsgBox Err.Description, vbCritical, Err.Source End Sub Private Sub Initialize() ReDim Primes(0) Primes(0) = 2 List1.Clear End Sub Private Sub Form_Load() Initialize End Sub all |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > .Net Development > sieve of erasothenes for #s 2-2000000000 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|