' Sets up an array of flags as Eratosthenes did nomainwin WindowWidth =1000 WindowHeight = 700 UpperLeftX = 50 UpperLeftY = 50 button #john.b1, "Quit", [quit], LL, 150, 0 button #john.b2, "New upper limit", [limit], LL, 10, 0 texteditor #john.t1, 10, 10, 300, 340 textbox #john.tb1, 10, 580, 100, 20 textbox #john.tb2, 150, 580, 100, 20 graphicbox #john.g1, 10, 360, 300, 200 graphicbox #john.g2, 330, 10, 642, 606 open "Eratosthenes Sieve in action...." for window as #john #john, "trapclose [quit]" #john.t1, "!font arial 10" #john.t1, "(1)is unique." #john.tb1, "Started- "; time\$() #john.g1, "font arial_bold 10 ; up ; place 10, 30 ; down" #john.g1, "\I am working" #john.g1, "up ; place 10 60" #john.g1, "\See the start and finish times appear" #john.g1, "\and then the primes are listed." #john.g2, "down ; fill black ; color white" topinteger =40000 [start] #john.t1, "Testing all integers up to "; #john.t1, topinteger dim ints( topinteger) for j =1 to topinteger ints( j) =1 scan next j #john.g1, "\Array zeroed" #john.g1, "\Now striking out primes and their multiples" for j =2 to 1 +topinteger^0.5 if ints( j) =1 then gosub [strikeout] scan next j #john.g1, "\Non primes struck out" #john.g1, "\Printing remainder as being prime" #john.t1, "!cls" #john.g1, "font arial_bold 10" for j =2 to topinteger if ints( j) =1 then #john.t1, j scan next j #john.tb2, "Finished- "; time\$() #john.g1, "place 10 160" #john.g1, "\FINISHED! Screen can be saved" #john.g1, "\ & primes list is selected." #john.g1, "flush" #john.g2, "flush" '#john.g2, "print" #john.g2, "getbmp drawing 1 1 641 605" filedialog "Save As...", "primes.bmp", fileName\$ bmpsave "drawing", fileName\$ #john.t1, "!selectall" '#john.t1, "!copy" causes problem if too long for clipboard! wait [strikeout] call setxy, i #john.t1, "Striking out "; #john.t1, j; #john.t1, "'s multiples." for k =2 *j to topinteger step j ints( k) =0 call setxy, k next k return [limit] prompt "John F asks" +chr\$(13) +"What upper limit do you want? (3 to 380000"; in\$ topinteger =int( val( in\$)) if topinteger <3 or topinteger >380000 then topinteger =20000 notice "Not allowed!" + chr\$(13) + "Replaced by 20000" +chr\$( 13) +"Since <3 or >380000" end if #john.g1, "cls ; place 10 30 ; color black" #john.g2, "cls ; fill black" #john.t1, "!cls" #john.tb1, "" #john.tb2, "" #john.tb1, "Started- "; time\$() goto [start] sub setxy jf y =int( jf /641) x =jf -641 *y #john.g2, "set "; x; " "; y end sub [quit] close #john end