RSS Forums RSS

How do you calculate prime numbers??

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums
Reply
Posts: 1
Reputation: terrible@VB is an unknown quantity at this point 
Solved Threads: 0
terrible@VB terrible@VB is offline Offline
Newbie Poster

How do you calculate prime numbers??

  #1  
Oct 20th, 2008
So I'm taking this introductory class on Visual Studio 2008 and I've been pretty lost since it started. Our current project is to write a code that will allow you to type in a starting and ending point then click the calculate button to calculate the factors of each number in the current range and display that in listbox1 then lablel1 needs to have a count of all the prime numbers that exist in that range and listbox 2 needs to show a list of all those prime numbers. My code currently calculates all of the factors in the range but I need help calculating the prime numbers and showing the count in label1 and the actual numbers in listbox2. If anyone has any suggestions they would be greatly appreciated. Here is my current code, i know its sloppy so if you have any suggestions to clean it up they would be appreciated as well.


Private Sub CalculateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateToolStripMenuItem.Click

Dim beginInteger, endInteger As Integer
Dim primeInteger, prime1Integer, displayInteger As Integer
Dim remainderInteger, primeNumberInteger As Integer
Dim outputString As String

beginInteger = CInt(fromTextBox.Text)
endInteger = CInt(toTextBox.Text)
ListBox1.Items.Add(" N Factors")

primeInteger = 0

For primeInteger = beginInteger To endInteger
displayInteger = primeInteger.ToString("D4")
outputString = Format(prime1Integer, "0000") & " "


For prime1Integer = 1 To primeInteger
remainderInteger = primeInteger Mod prime1Integer
If remainderInteger = 0 Then
'primeNumberInteger += 1
outputString &= " " & prime1Integer
End If




Next
ListBox1.Items.Add(outputString)

Next

End Sub
AddThis Social Bookmark Button
Reply With Quote  
Posts: 291
Reputation: jireh is an unknown quantity at this point 
Solved Threads: 37
jireh's Avatar
jireh jireh is offline Offline
Posting Whiz in Training

Re: How do you calculate prime numbers??

  #2  
Oct 21st, 2008
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 1695 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:00 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC