# Microsoft Small Basic

Program Listing:
'Challenge of the Month - December 2013 Prime Number by NaochanON WXB989-1
' 60sec .... No: 11609 th PrimeNo=123527
' Thanks WhTurner 33
init()

Controls.ButtonClicked=onclicked

Sub onclicked
calctime= Controls.GetTextBoxText(box1)
calcprime()
EndSub

Sub calcprime
Prime=""
div="1=2;2=3;"
NN=2
a=3
t1=0
t0=clock.ElapsedMilliseconds
While t1 <= Calctime
divided=1                                  '"Yes"
a=a+2                                      ' odd number only
sqr = Math.SquareRoot(a)
If (sqr*sqr-a)<>0 Then
divided=0
For i =2 To NN
If div[i]>sqr then                     ' a=b*c bsqr
i=NN
EndIf
If math.Remainder(a,div[i])=0 Then     ' if divided or not
i=NN
divided=1                            '"Yes"
EndIf
EndFor
EndIf
If divided=0  Then                         ' "No"
NN=NN+1
div[NN]=a                                ' Prime number array
EndIf
t1=(Clock.ElapsedMilliseconds-t0)/1000
EndWhile
For j= NN-4 To NN
Prime=Prime+j+"= "+div[j]+" ; "
endfor
LF=Text.GetCharacter(10)
Controls.SetTextBoxText(box2,msg1+LF+LF+Prime)
EndSub

Sub init
GraphicsWindow.BackgroundColor="lightcyan"
GraphicsWindow.Width=600
GraphicsWindow.Height=250
GraphicsWindow.Left=20
GraphicsWindow.top=20
GraphicsWindow.FontSize=14
Controls.SetSize(box1,150,40)
Controls.SetSize(btn,80,40)
GraphicsWindow.FontSize=12
msg1="Input calculation time <=60 and Push Calc button"
Controls.SetSize(box2,500,80)
Controls.SetTextBoxText(box2,msg1)
EndSub