Thread: Redim Problem
View Single Post
Old Sep 22nd, 2004, 10:09 AM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
Some of your variables are misspelled, others are undefined... I don't have VB on hand right now, but try this:

Public Function prime(ByVal x As Integer)
    Dim primes(0) As Integer
    Dim bound, y, Index 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(bound + 1)
        primes(bound + 1) = y
      End If
    Next y
  End Function
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote