467,151 Members | 903 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,151 developers. It's quick & easy.

Primes Numbers

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
  • viewed: 2484
Share:
4 Replies
1GB
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+
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
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+
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.

By using this site, you agree to our Privacy Policy and Terms of Use.