# Verification for finding prime numbers

## Recommended Posts

I can not for the life of me get this to work, the script finds prime numbers just fine and logs them in a nice way, but I can not get it to reject text, negative numbers and/or numbers with a decimal point. Here's what I have so far, it just opens the input box in an infinite loop no matter what I type in. The verification is in the first 'Do' loop.

```\$okpass = 0
\$number = 1
\$limit = InputBox( "the limit", "what would you lke to make the limit?")
\$errtest = IsNumber(\$limit) + IsInt(\$limit)
Do
\$isnumber = IsNumber(\$limit)
\$isint = IsInt(\$limit)
If \$isnumber == 0 Or \$isint == 0 or \$limit <= 0 Then
\$limit = InputBox( "the limit", "please input a valid integer. Letters, numbers with decimal places and negative numbers will not work!")
ElseIf
\$okpass = 1
EndIf

Until \$okpass == 1

Do ; resets everything each time the number is increased
\$number += 1
\$tempnum = 1
\$no = 0
\$next = 0
isprime()
Until \$number >= \$limit

Func isprime() ; checks to see if the variable is a prime number using a loop
If \$number > 3 then
Do
\$tempnum += 1
\$test = \$number / \$tempnum
If IsInt ( \$test ) Then
\$no = 1
Else
\$next += 1
EndIf

If \$next >= (\$number / 2) Then
FileWrite(@ScriptDir & "primenumbers.txt", \$number & ", ")
\$no = 1
EndIf
Until \$no == 1
Else
FileWrite(@ScriptDir & "primenumbers.txt", \$number & ", ")
EndIf
EndFunc```

Edited by itsnotluketime

##### Share on other sites
`\$limit = Int(InputBox( "the limit", "what would you lke to make the limit?"))`

Maybe

Monkey's are, like, natures humans.

##### Share on other sites

The greatest with AutoIt findable prime using a Array for solving  (limitation of Array) without using any UDF is 16777213. There are 1077870 smaller primes in this range. Found with a AutoItscript < 290 sec.

Attached Primes.zip contains textfile with the primes and DemoPrimes.exe,  AV-Test: SHA256:1267ddf7cc6a0a7bb0a7b6e064242fe452ddefd936a3f0adcea6ee761b830fa4

The func i used is the only one in a UDF i was Co-Author.

Edited by AutoBert

## Create an account

Register a new account

×

• Wiki

• Back

• Git