| | |
How do you calculate prime numbers??
![]() |
•
•
Join Date: Oct 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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
Try this...
1. http://www.xtremecomp.com/tips/xttip19.htm
2. http://forums.invisionpower.com/lofi...p/t210744.html
3. http://social.msdn.microsoft.com/For...-a73ff6f4abaa/
I just google it for you seems you don't want to do it... ahehehehe
1. http://www.xtremecomp.com/tips/xttip19.htm
2. http://forums.invisionpower.com/lofi...p/t210744.html
3. http://social.msdn.microsoft.com/For...-a73ff6f4abaa/
I just google it for you seems you don't want to do it... ahehehehe
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
![]() |
Similar Threads
- Print Prime Numbers(using for loop) (C)
- finding prime numbers that add up to even number? (C)
- strtoul() function use (C++)
- java (Java)
- please send me complete artical about the question (Computer Science)
- Average of prime number between 1 & 100 (C#)
- Reverse Output (Stack) (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: opening a database from vb6
- Next Thread: Time Difference in VB 6.0
| Thread Tools | Search this Thread |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading refresh remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





