[table="width: 500"]
[tr]
[td]Function PrimeCountBetween(FromNumber As Long, ToNumber As Long) As Long
Dim X As Long, NthPrime As Long, Test As Long, Sum As Long, Results As Variant
Const MaxPrime As Long = 20000003
Static Initialized As Boolean, PrimesFlag() As Byte
If FromNumber > 0 And FromNumber < ToNumber And ToNumber < 20000001 Then
If Not Initialized Then
Initialized = True
PrimesFlag = ChrW(1) & ChrW(257) & String(10000000, ChrW(256))
Test = 3
Do While Test <= MaxPrime
For X = 2 * Test To MaxPrime Step Test
PrimesFlag(X) = 0
Next
Test = Test + 1 - (Test > 2)
Loop
End If
For X = FromNumber To ToNumber
If PrimesFlag(X) = 1 Then PrimeCountBetween = PrimeCountBetween + 1
Next
Else
PrimeCountBetween = -1
End If
End Function[/td]
[/tr]
[/table]