xShadowx Posted September 23, 2008 Share Posted September 23, 2008 I am having trouble making a progress bar. I have been hacking away at the one in the help file. This is what I got. #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> progress() Func progress() GUICreate("Progress", 220, 77, 619, 451) $progressbar = GUICtrlCreateProgress(6, 10, 208, 30) GUICtrlSetColor(-1, 32250) $button = GUICtrlCreateButton("Finished", 75, 50, 70, 20) $button1 = GUICtrlCreateButton("About", 145, 50, 70, 20) $button2 = GUICtrlCreateButton("Exit", 5, 50, 70, 20) GUISetState() $wait = 45 $s = 0 While 1 $msg = GUIGetMsg() GUICtrlSetData($button, "Working...") For $i = $s To 100 GUICtrlSetData($progressbar, $i) Sleep($wait) Next If $i > 100 Then GUICtrlSetData($button, "Finished") EndIf WEnd EndFunc It is all but perfect. All help is appreciated. Link to comment Share on other sites More sharing options...
martin Posted September 23, 2008 Share Posted September 23, 2008 I am having trouble making a progress bar. I have been hacking away at the one in the help file. This is what I got. #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> progress() Func progress() GUICreate("Progress", 220, 77, 619, 451) $progressbar = GUICtrlCreateProgress(6, 10, 208, 30) GUICtrlSetColor(-1, 32250) $button = GUICtrlCreateButton("Finished", 75, 50, 70, 20) $button1 = GUICtrlCreateButton("About", 145, 50, 70, 20) $button2 = GUICtrlCreateButton("Exit", 5, 50, 70, 20) GUISetState() $wait = 45 $s = 0 While 1 $msg = GUIGetMsg() GUICtrlSetData($button, "Working...") For $i = $s To 100 GUICtrlSetData($progressbar, $i) Sleep($wait) Next If $i > 100 Then GUICtrlSetData($button, "Finished") EndIf WEnd EndFunc It is all but perfect. All help is appreciated. Here's one way to do it. Sorry I've messed your script up a bit. expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> progress() Func progress() GUICreate("Progress", 220, 77, 619, 451) $progressbar = GUICtrlCreateProgress(6, 10, 208, 30) GUICtrlSetColor(-1, 32250) $button = GUICtrlCreateButton("Finished", 75, 50, 70, 20) $button1 = GUICtrlCreateButton("About", 145, 50, 70, 20) $button2 = GUICtrlCreateButton("Exit", 5, 50, 70, 20) GUISetState() $wait = 45 $s = 0 $progres = 0 $i = 0 GUICtrlSetData($button, "Working...") $tp = TimerInit() While 1 $msg = GUIGetMsg() If $msg = $button2 Or $msg = $GUI_EVENT_CLOSE Then Return If $i < 100 Then If TimerDiff($tp) >= $wait Then $i += 1 GUICtrlSetData($progressbar, $i) If $i = 100 Then GUICtrlSetData($button, "Finished") Else $tp = TimerInit() EndIf EndIf EndIf WEnd EndFunc ;==>progress In your script (the one you posted) it would set the progress bar then start the while/wend loop again which start the progress bar from 0 again. It also meant there was not much chance of responding to the buttons. I think a better way to do it would be using OnEvent mode and you could have a simpler script than the one above and more like yours. expandcollapse popup#include <GUIConstantsEx.au3> #include <ProgressConstants.au3> Opt("GuiOnEventMode", 1) progress() Func progress() GUICreate("Progress", 220, 77, 619, 451) $progressbar = GUICtrlCreateProgress(6, 10, 208, 30) GUICtrlSetColor(-1, 32250) $button = GUICtrlCreateButton("Working...", 75, 50, 70, 20) GUICtrlSetOnEvent(-1, "Btn0Event") $button1 = GUICtrlCreateButton("About", 145, 50, 70, 20) GUICtrlSetOnEvent(-1, "Btn1Event") $button2 = GUICtrlCreateButton("Exit", 5, 50, 70, 20) GUICtrlSetOnEvent(-1, "Btn2Event") GUISetState() GUISetOnEvent($GUI_EVENT_CLOSE, "Btn2Event") $wait = 45 $tp = TimerInit() While 1 If GUICtrlRead($progressbar) < 100 Then For $i = 0 To 100 GUICtrlSetData($progressbar, $i) Sleep($wait) If $i = 100 Then GUICtrlSetData($button, "Finished") Next EndIf WEnd EndFunc ;==>progress Func Btn0Event() EndFunc ;==>Btn0Event Func Btn1Event() EndFunc ;==>Btn1Event Func Btn2Event() Exit EndFunc ;==>Btn2Event Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
xShadowx Posted September 23, 2008 Author Share Posted September 23, 2008 Oh mate, you are the best. Thanks martin. 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