Function ISPRIME ( N as long) As Boolean Select Case N Case 0 ISPRIME =false Exit Function Case 1 ISPRIME =false Exit Function Case 2 ISPRIME =true Exit Function End Select If N mod 2 = 0 Then ISPRIME = false Exit Function End If Dim M as long M = Int(Sqr(N)) +1 For i=3 To M Step 2 If N mod i = 0 Then ISPRIME = false Exit Function End if Next i ISPRIME = true End Function