The first thing you should do is figure out how to print n prime numbers - that will solve all of your problems.

Code:

function printprimes(primes as integer)
dim i as long
dim counter as integer
i=1
do while primes <> counter
if prime(i) then counter = counter + 1
i=i+1
loop
end function
function prime(checkprime as long)
do your prime check here....
end function