Need some help with VB (prime numbers and factors) Tags: Programming Apps Last response: September 29, 2010 12:15 AM in Applications Share pinnacle2009 September 27, 2010 10:31:12 PM I am trying to get a VB program that will determine whether or not a user-generated number is prime or not. Right now, all I have is this: Dim num As Integer Dim factor As Integer factor = 1 num = TextBox1.Text Do While num >= factor If num Mod factor = 0 Then RichTextBox1.AppendText(vbCrLf & factor) End If factor = factor + 1 Loop It's just getting the factors of a number. I cannot get it to tell prime numbers apart, however. Any help? More about : prime numbers factors pinnacle2009 September 28, 2010 12:33:09 PM Okay, after looking and and searching, I now have: Dim num As Integer Dim i As Integer Dim counter As Integer num = TextBox1.Text counter = 0 i = 1 Do While i <= num If num Mod i = 0 Then counter = counter + 1 End If i = i + 1 Loop If counter = 2 Then TextBox2.Text = "This is a prime number!" Else TextBox2.Text = "This is NOT a Prime number!" End If However, I don't know what the counter does exactly.. (part of this was copied) Could someone explain? kyeana a b L Programming September 28, 2010 2:00:35 PM Here is a hint, the defination of a prime number is a number that can be divided by one and itself. Go through the code line by line and see if you can't understand what it is doing. Can't find your answer ? Ask ! Get the answer pinnacle2009 September 29, 2010 12:15:15 AM got it now. we actually just did stuff with it in class today. Can't find your answer ? Ask ! Publish Related resources: ForumMetroid Prime 2 impressions ForumNeed help with VB ForumI5-2500K Overheating 92 C (under prime 95) ForumIbt and prime Forum[ vb ] Is it possible to read a file as (start-half) and (half-end)? ForumQ6600 4th core keeps failing in Prime 95: need help ForumCore i7 runs TOO HOT with Prime 95 & side panel attached! ForumCan CPU be Fired if Prime stable at stock? ForumVB .NET running on network share Forum1.55v for my 1100T to be stable at 4ghz with prime 95 safe? ForumPrime 95 help ForumComputer won't boot; factors : msconfig, system restore, malware doctor Forum3770k over heating Prime 95 ForumI7 870 won't go to full 3.60 Turbo Boost in prime 95? ForumPrime 95 is stuck ForumNew K7N2 Delta-L system hanging in Prime 95 ForumWhat is the difference between Extended and normal version of a software? ForumSyncing outlook with gmail contacts and vice versa ForumNeed help with Hypercam 2 and video compression. ForumI'm having a weird issue with a character... More resources Read discussions in other Applications categories Graphics Internet Applications Multimedia Office Security CAD Distributed Computing Drivers Enterprise Software Firmware Programming Photoshop Skype Wordpress !