Thread: Redim Problem
View Single Post
Old Sep 22nd, 2004, 9:48 AM   #1
Johnny_English
Newbie
 
Join Date: Sep 2004
Posts: 7
Rep Power: 0 Johnny_English is on a distinguished road
Hello,
I'm a beginner in VB and I'm having trouble with my code. It's a prime number calculator. Here is the function:

Public Function prime(x As Integer)
  Dim primes(0) As Integer
  primes(0) = 2
  For y = 2 To x
    bound= UBound(primes)
    For Index = 0 To bound
      If (y Mod primes(Index)) = 0 Then
        Exit For
      End If
    Next Index
    If Index = bound Then
        ReDim Preserve primes(boun + 1)
        primes(bound + 1) = y
    End If
  Next y
End Function
It receives the argument x passed by main.

When I run the code I get "Array already dimentioned."
Johnny_English is offline   Reply With Quote