kaasknak Posted March 21, 2012 Share Posted March 21, 2012 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 Link to comment Share on other sites More sharing options...
kaasknak Posted April 4, 2012 Author Share Posted April 4, 2012 bump Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 4, 2012 Moderators Share Posted April 4, 2012 kaasknak,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 $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 WEndIf 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kaasknak Posted April 5, 2012 Author Share Posted April 5, 2012 Thanks I am going to try this. Link to comment Share on other sites More sharing options...
kaasknak Posted April 5, 2012 Author Share Posted April 5, 2012 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 Link to comment Share on other sites More sharing options...
Zedna Posted April 5, 2012 Share Posted April 5, 2012 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 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now