By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,594 Members | 2,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,594 IT Pros & Developers. It's quick & easy.

Primes Numbers

P: 5
Hallo
I have a problem. I want to make a program in Visual Basic 2005. It should find and print prime numbers. I do not know how to make it. Can someone helps me.

Thanks
Nov 12 '06 #1
Share this Question
Share on Google+
4 Replies


100+
P: 1,646
Hallo
I have a problem. I want to make a program in Visual Basic 2005. It should find and print prime numbers. I do not know how to make it. Can someone helps me.

Thanks
Hi. Can you tell us please if your difficulty is in programming or in working out an algorithm to generate prime numbers?

BTW you may get a more accurate answer in the .NET forum as you are using vb.NET.
Nov 12 '06 #2

100+
P: 267
Hallo
I have a problem. I want to make a program in Visual Basic 2005. It should find and print prime numbers. I do not know how to make it. Can someone helps me.

Thanks
hi
don't know about 2005, but in VB6 you may use this example:
create a form with a listbox (List1)

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub Form_Load()
  3. Dim prime As New Collection
  4. prime.Add 1                         'actually 1 is a special number
  5. prime.Add 2                         '2 is the first real prime
  6. For i = 3 To 1000                   'start searching from 3 to whatever number (1000)
  7. NoPrime = False                     'assume primenumber
  8.     For dev = 2 To prime.Count - 1  'try to devide actuale number by all other primes
  9.     If i Mod prime(dev) = 0 Then    'if devision has no remains then no prime
  10.        NoPrime = True
  11.        Exit For
  12.     End If
  13.     Next dev                        'if i is a prime, add to collection
  14.     If NoPrime = False Then prime.Add i
  15. Next i
  16.  
  17. For i = 1 To prime.Count - 1        'if all are done, put into the list
  18. List1.AddItem prime(i)
  19. Next i
  20.  
  21. End Sub
  22.  
  23.  
Nov 12 '06 #3

P: 5
Hi. Can you tell us please if your difficulty is in programming or in working out an algorithm to generate prime numbers?

BTW you may get a more accurate answer in the .NET forum as you are using vb.NET.

I know the algorithm but I have problem in programming
Nov 15 '06 #4

100+
P: 267
I know the algorithm but I have problem in programming
guess your in the wrong forum then.... :(
Nov 15 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.