.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 22nd, 2003, 12:28 PM
cinderic cinderic is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 1 cinderic User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > sieve of erasothenes for #s 2-2000000000


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT