## Recommended Posts

Hello,

I've created this program that calculates pi if you let it run an infinite number of calculations.

Because large numbers may take some time to calculate I want to add a progress bar.

Also I want the input to be numbers only.

Can someone help me?

This is my current script

```while 1
\$aantal=InputBox("Invoer", "Vul in hoeveel berekeneningen de computer moet uitvoeren."& @CRLF &"Hoe groter het getal hoe meer het van je computer vraagt.")
if \$aantal = 0 then
Exit
Else
\$noemer=1
Do
\$temp=1/(\$noemer^2)
\$noemer=\$noemer+1
Until \$noemer=\$aantal
EndIf
\$pi=sqrt(\$stap1)
\$u=MsgBox(325, "uitkomst", "Volgens je benadering:"& @CRLF &"pi="&\$pi)
If \$u=2 then Exit
WEnd```

Can someone help me?

thanks

##### Share on other sites
• 2 weeks later...

bump

##### Share on other sites
• Moderators

Welcome to the AutoIt forum.

Here is how you could add a simple progressbar to your script:

```While 1
\$aantal = InputBox("Invoer", "Vul in hoeveel berekeneningen de computer moet uitvoeren." & @CRLF & "Hoe groter het getal hoe meer het van je computer vraagt.")
ProgressOn ("Calulating", "Progress", 0)
If \$aantal = 0 Then
Exit
Else
For \$noemer = 1 To \$aantal
ProgressSet( \$noemer / \$aantal * 100, \$noemer)
\$temp = 1 / (\$noemer ^ 2)

; Just to slow it down so you can see the progress increase for small numbers
Sleep(1000)
; Remove these lines if you use BIG numbers!

Next
EndIf
ProgressOff()
\$pi = Sqrt(\$stap1)
If MsgBox(325, "uitkomst", "Volgens je benadering:" & @CRLF & "pi=" & \$pi) = 2 Then
Exit
EndIf
WEnd```

If you want to limit the input to digits only then you will have to create your own GUI using an input control with the \$ES_NUMBER style. But you could always use Number on \$aantal to convert it.

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

##### Share on other sites

Thanks I am going to try this.

##### Share on other sites

After some slight adaption it worked just the way I wanted it to work.

Here is my new code.

```While 1
\$aantal = InputBox("Invoer", "Vul in hoeveel berekeneningen de computer moet uitvoeren." & @CRLF & "Hoe groter het getal hoe meer het van je computer vraagt.")
ProgressOn ("Berekenen", "Vooruitgang", 0)
If \$aantal = 0 Then
Exit
Else
For \$noemer = 1 To \$aantal
ProgressSet( \$noemer / \$aantal * 100, Round (\$noemer / \$aantal * 100, 1) & "%")
\$temp = 1 / (\$noemer ^ 2)
Next
EndIf
ProgressOff()
\$pi = Sqrt(\$stap1)
If MsgBox(325, "uitkomst", "Volgens je benadering:" & @CRLF & "pi=" & \$pi) = 2 Then
Exit
EndIf
WEnd```
##### Share on other sites

To avoid flickering and much higher calculation speed use this:

```Global \$percent_prev

While 1
\$aantal = InputBox("Invoer", "Vul in hoeveel berekeneningen de computer moet uitvoeren." & @CRLF & "Hoe groter het getal hoe meer het van je computer vraagt.")
ProgressOn ("Berekenen", "Vooruitgang", 0)
If \$aantal = 0 Then
Exit
Else
For \$noemer = 1 To \$aantal
\$percent = Round (\$noemer / \$aantal * 100, 1)
If \$percent <> \$percent_prev Then
ProgressSet( \$percent, \$percent & "%")
\$percent_prev = \$percent
EndIf
\$temp = 1 / (\$noemer ^ 2)
Next
EndIf
ProgressOff()
\$pi = Sqrt(\$stap1)
If MsgBox(325, "uitkomst", "Volgens je benadering:" & @CRLF & "pi=" & \$pi) = 2 Then
Exit
EndIf
WEnd```

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...