Jump to content
Sign in to follow this  
kaasknak

progress bar addition

Recommended Posts

kaasknak

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
$benadering=0
$noemer=1
Do
$temp=1/($noemer^2)
$benadering=$benadering+$temp
$noemer=$noemer+1
Until $noemer=$aantal
EndIf
$stap1=$benadering*6
$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 this post


Link to post
Share on other sites
kaasknak

bump

Share this post


Link to post
Share on other sites
Melba23

kaasknak,

Welcome to the AutoIt forum. :oops:

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
        $benadering = 0
        For $noemer = 1 To $aantal
            ProgressSet( $noemer / $aantal * 100, $noemer)
            $temp = 1 / ($noemer ^ 2)
            $benadering = $benadering + $temp

            ; 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()
    $stap1 = $benadering * 6
    $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. :bye:

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______Open 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 this post


Link to post
Share on other sites
kaasknak

Thanks I am going to try this.

Share this post


Link to post
Share on other sites
kaasknak

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

Thanks for your help.

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
        $benadering = 0
        For $noemer = 1 To $aantal
            ProgressSet( $noemer / $aantal * 100, Round ($noemer / $aantal * 100, 1) & "%")
            $temp = 1 / ($noemer ^ 2)
            $benadering = $benadering + $temp
        Next
    EndIf
    ProgressOff()
    $stap1 = $benadering * 6
    $pi = Sqrt($stap1)
    If MsgBox(325, "uitkomst", "Volgens je benadering:" & @CRLF & "pi=" & $pi) = 2 Then
        Exit
    EndIf
WEnd

Share this post


Link to post
Share on other sites
Zedna

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
        $benadering = 0
        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)
            $benadering = $benadering + $temp
        Next
    EndIf
    ProgressOff()
    $stap1 = $benadering * 6
    $pi = Sqrt($stap1)
    If MsgBox(325, "uitkomst", "Volgens je benadering:" & @CRLF & "pi=" & $pi) = 2 Then
        Exit
    EndIf
WEnd

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×