Just to complete this I have added a precision box, timer and the programme now outputs "Pi.txt" to allow it to be printed.

Enter the number of digits required in the box and click start. When done the time taken is displayed and you will find Pi.txt in the folder ready to be printed. The QuadsPerLine variable can be adjusted to set how many four digit sequences are printed across a line so adjust this for your paper width to print. I think 20 is about A4 portrait width.

**Code:**

#SCALE = 10000

#ARRINT= 2000

Global Window_0

Global btnStart, btnCancel, strTime, txtTime

Global ElapsedSeconds.d,Running.i,NumberOfDigits.i,DigitsRequired.i,QuadsPerLine.i,Iterations.i

DigitsRequired = 1000

QuadsPerLine = 20

Procedure Pi()

Protected First=#True, Text$

Protected Carry, i, j, sum

Iterations = 0

Digits = 24 * 1024

NumberOfDigits = 0

Dim Arr(Digits)

For i=0 To Digits

Arr(i)=#ARRINT

Next

i=Digits

While i>0

sum=0

j=i

While j>0

sum*j+#SCALE*arr(j)

Arr(j)=sum%(j*2-1)

sum/(j*2-1)

j-1

Wend

Text$ = RSet(Str(Carry+sum/#SCALE),4,"0")

If First

Text$ = ReplaceString(Text$,"3","3.")

First = #False

EndIf

NumberOfDigits = NumberOfDigits + 4

If NumberOfDigits => DigitsRequired

Break

Else

If Iterations = QuadsPerLine - 1

WriteStringN(0, " " + text$)

Iterations = 0

Else

WriteString(0, " " + text$)

Iterations = Iterations + 1

EndIf

EndIf

Carry=sum%#SCALE

i-14

Wend

EndProcedure

Window_0 = OpenWindow(#PB_Any, 0, 0, 200, 110, "Pi Tester", #PB_Window_SystemMenu)

txtPrecision = TextGadget(#PB_Any, 10, 10, 70, 20, "Precision", #PB_Text_Right)

strPrecision = StringGadget(#PB_Any, 90, 10, 100, 20, "")

btnStart = ButtonGadget(#PB_Any, 90, 40, 100, 30, "Start")

strTime = StringGadget(#PB_Any, 90, 80, 100, 20, "")

txtTime = TextGadget(#PB_Any, 10, 80, 130, 20, "Time Taken")

AddWindowTimer(Window_0, 1, 100)

Running = #False

Repeat

Event = WaitWindowEvent()

Select event

Case #PB_Event_CloseWindow

End

Case #PB_Event_Gadget

Select EventGadget()

Case btnStart

If Val(GetGadgetText(strPrecision)) > 24*1024*1024

MessageRequester("Precision Error","Maximum precision allowed = " + Str(24*1024*1024))

Else

If CreateFile(0, "Pi.txt")

DigitsRequired = Val(GetGadgetText(strPrecision))

SetGadgetText(strTime,"")

ElapsedSeconds = ElapsedMilliseconds()

Running = #True

pi()

ElapsedSeconds = ElapsedMilliseconds()-ElapsedSeconds

Running = #False

CloseFile(0)

EndIf

EndIf

SetGadgetText(strTime,StrD(ElapsedSeconds/1000) + " Secs")

Case btnCancel

Running = #False

EndSelect

EndSelect

ForEver