Sign in to follow this  
Followers 0
triodz

Difficulty in making a progress bar move

10 posts in this topic

I have been trying to get a progress bar to, well, progress. I have looked at several scripts on here and most of them relate to copying files across, which I do not want to do. I tried chopping it up to suit my needs, but just break them.

I simply want the user to press the "Start" button and the bar to run for a few seconds (15 or 20 seconds. Less is fine), then show them a completed message.

Here is what I have so far:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ###
Opt("GUIOnEventMode", 1)
$Form1_1 = GUICreate("Form1", 506, 223, 236, 128)
$Exit = GUICtrlCreateButton("Exit", 336, 144, 129, 41)
GUICtrlSetOnEvent($GUI_EVENT_CLOSE, "close");
$Button1 = GUICtrlCreateButton("Start", 184, 144, 129, 41)
GUISetState (@SW_SHOW)
$Progress1 = GUICtrlCreateProgress(16, 104, 465, 17)
GUISetState()
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

Case $Exit
EndSwitch
WEnd
$wait = 20
$s = 0
do
$nmsg = GUIGetMsg()
If $nmsg = $Button1 Then
    For $i = $s To 100
    If GUICtrlRead($progress1) = 100 Then Msgbox(0,"Info","Complete!", 1)
    $m = GUIGetMsg ()

    If $m = -3 Then ExitLoop

        $s=0
      GUICtrlSetData ($progress1,$i)
      Sleep($wait)
    Next
    if $i >100 then
    endif
EndIf
until $nmsg = $GUI_EVENT_CLOSE
func close ()
Exit
EndFunc

Pressing the exit button works fine. The bar is there, but no progress shows. It's more for the user so they know something is happening. All I want it to do is turn green from start to finish when "Start" is pressed.

I am very new and I know the aesthetics need work, but I just need to get over this hurdle first.

Thanks for any help on this one. I have had nothing but wonderful help from this community in the past!

Thanks in advance

Share this post


Link to post
Share on other sites



triodz, couple of things to point out.

First you shouldnt use GUIOnEventMode and GUIGetMsg() in the same script. Pick one or the other. Also the reason nothing happens with the progress bar is the script never reaches that far. After your gui is create, your script goes into an endless "while" loop. Put your progress bar code into a function and then call that function when the start button is pressed.

Share this post


Link to post
Share on other sites

Thanks Beege,

I tried the below with your suggestions, but still having trouble. I just don't know what I'm doing wrong.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### 
Opt("GUIOnEventMode", 1);
$Form1_1 = GUICreate("Form1", 506, 223, 236, 128)
$Exit = GUICtrlCreateButton("Exit", 336, 144, 129, 41)
GUIctrlSetOnEvent($GUI_EVENT_CLOSE, "close")
$Button1 = GUICtrlCreateButton("Start", 184, 144, 129, 41)
GUIctrlSetOnEvent($GUI_EVENT_CLOSE, "progress")
GUISetState (@SW_SHOW)
$Progress1 = GUICtrlCreateProgress(16, 104, 465, 17)
GUISetState()
#EndRegion ### END Koda GUI section ###

func progress ()
$wait = 20
$nmsg = GUIGetMsg()
If $nmsg = $Button1 Then
    For $i = 0 To 100
    If GUICtrlRead($Progress1) = 100 Then Msgbox(0,"Info","Complete!", 1)
Next
EndIf
EndFunc
func close ()
Exit
EndFunc
While 1
sleep(10)
WEnd

It's driving me nuts!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ok.. that code is better though. You removed alot of the code that was not being used at all. But you still using GUIOnEventMode, and GUIGetmsg() in the same script. GUIOnEventMode lets you assign a function to be called whenever a certian event happens. GUIGetMsg() is designed to retrive the event msgs and then let you handle what happens with that event. Using both at the same time kinda makes them fight each other. Understanding these concepts will become more clear in time.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ###
;Use OnEventMode
Opt("GUIOnEventMode", 1);

;Create GUI
$Form1_1 = GUICreate("Form1", 506, 223, 236, 128)

;create Exit button
$Exit = GUICtrlCreateButton("Exit", 336, 144, 129, 41)
;If exit button is pressed, call "close" function
GUICtrlSetOnEvent($Exit, "close")

;If a close event happens call "close" function
GUICtrlSetOnEvent($GUI_EVENT_CLOSE, "close")

;create start button
$Button1 = GUICtrlCreateButton("Start", 184, 144, 129, 41)
;If $button1 is pressed call function "progress"
GUICtrlSetOnEvent($Button1, "progress")

;create progress bar
$Progress1 = GUICtrlCreateProgress(16, 104, 465, 17)

;Show the gui
GUISetState()
#endregion ### END Koda GUI section ###

;loop around and just wait for any events to happen
While 1
Sleep(10)
WEnd

Func progress()
$wait = 20
For $i = 0 To 100
  GUICtrlSetData($Progress1, $i)
  Sleep($wait)
Next
EndFunc   ;==>progress

Func close()
  Exit
EndFunc   ;==>close
Edited by Beege

Share this post


Link to post
Share on other sites

Oh, I see what you did. I knew I was missing something simple. Thanks so much! I really appreciate your help! I also found this:

http://www.autoitscript.com/wiki/Progress_Bar_Sample

for anyone who happens upon this thread. Gives them a couple of options.

Thanks again Beege, you've been great!

Share this post


Link to post
Share on other sites

Your welcome. :) Look into starting to use GUIGetMsg(). Oneventmode is easy, but limits you. For example, change $wait to 100. Then while the progress bar is increasing try and press the exit or close button. You will notice a small problem...

Share this post


Link to post
Share on other sites

Your welcome. :) Look into starting to use GUIGetMsg(). Oneventmode is easy, but limits you. For example, change $wait to 100. Then while the progress bar is increasing try and press the exit or close button. You will notice a small problem...

Wouldn't using the message loop mode display the same problem? While the function is running, no button presses will be activated until that function ends. OnEventMode causes you to create more functions than MessageLoop mode, but works easier when dealing with multiple GUIs, as an example, for the new user.

I'd learn to use the GUIRegisterMsg functions so that you can eliminate 90% of the delay problems exhibited with long running functions you want to interrupt. Then it won't matter if you're using messageloop or onevent modes.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Wouldn't using the message loop mode display the same problem?

Yes it would, but using msg loop mode you can fix the problem much easier by adding msg checks with in the function. Its harder to pull that off using only onevent mode. (as you pretty much state in the next comment) :)

I'd learn to use the GUIRegisterMsg functions so that you can eliminate 90% of the delay problems exhibited with long running functions you want to interrupt. Then it won't matter if you're using messageloop or onevent modes.

Not sure I follow. Your saying learn to use GUIRegistermsg (message loop), then it wont matter if your using message loop or onevent?

Share this post


Link to post
Share on other sites

GUIRegisterMsg (monitoring Windows messages) isn't the same as using GUIGetMsg (message loop mode).


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Ohhh. My bad. I read and typed GUIRegistermsg thinking GuiGetMsg(). :) You absolutely right.

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  
Followers 0

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      hello
      please i need to link a progress bar with a time can you help me?
      e.g
      i want to set a progress bar for 10 sec
      am waiting for your answers
      thank you.
    • FroVN
      By FroVN
      Hi, i'm code software listen music on GUI, it's show time playing, hotkey pause/play music, and the last i missing that's the progress to seek the video to hour::ss:( i can't describe exactly, it's like a progress with red color we can backward or fast forward on youtube, i want do the same like that on my gui) i used to use guicreate slider, but it's not good, any idea give me, Tks(sorry for my bad english)
       

    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I want create retractable bar using autoit
      I tried creating slider, but there's a problem with screen reader for the blind, so is there another retractable tape?
      It is advisable to not accept dragging with the keybord only with  mouse
      note:
      This bar is needed in the process of raising and lowering the volume
      I hope that there is a solution to do that
      i waiting your responses.
      Thanks in advance to all members and administrators
    • RyukShini
      By RyukShini
      #include <ColorConstants.au3>; Including required files #include <GUIConstantsEx.au3> #include <file.au3> #include <Array.au3> #include <string.au3> Example() Func Example() Local $hash Local $hashes = "hash.txt" _FileReadToArray($hashes, $hash) For $i = 1 To UBound($hash) - 500 $hashcheck = $hash[$i] $PDenc = "hash=" & $hashcheck & "&decrypt=Decrypt" $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("POST", "http://myurl/", False) ; Post url $oHTTP.SetRequestHeader("Host", "myurl") $oHTTP.SetRequestHeader("Connection", "keep-aliveContent-Length: 29") $oHTTP.SetRequestHeader("Cache-Control", "max-age=0") $oHTTP.SetRequestHeader("Origin", "http://myurl") $oHTTP.SetRequestHeader("Upgrade-Insecure-Requests", "1") $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36") $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") $oHTTP.SetRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") $oHTTP.SetRequestHeader("Referer", "http://myurl") $oHTTP.SetRequestHeader("Accept-Language", "en-US,en;q=0.8") $oHTTP.Send($PDenc) $oReceived = $oHTTP.ResponseText $oStatusCode = $oHTTP.Status sleep(2000) If $oStatusCode = 503 then MsgBox(4096, "Response code", $oStatusCode) ExitLoop EndIf ; Saves the body response regardless of the Response code $file = FileOpen("Received.html", 2) ; The value of 2 overwrites the file if it already exists FileWrite($file, $oReceived) $read = FileRead("Received.html") ;read file if StringInStr($read, "not found") Then ContinueLoop Else ContinueLoop $Datastring = ('</script></div><br/>') $newreadamount = _StringBetween($read, $Datastring, "</b><br/><br/>") ;read title from file $newreadamount[0] = StringReplace($newreadamount[0], '<b>', "") ; taking out the X makes it easier to compare value If @error Then ContinueLoop EndIf $file = FileOpen("decrypted.txt", 1) FileWrite($file, $newreadamount[0] & @CRLF) EndIf Next sleep(2000) EndFunc ;==>Example As you can read my script loads 500 lines of text, lets say I have a list with 10.000 lines
      Is there a way to show a progressbar GUI to show how long in a text file I am?
      I may not know how long a particular .txt file is always so I am thinking I need some sort of algorythm?
      Thanks in advance.
      ( I just got unclear if I actually read 500 lines each attempt or if I start with 500 and add 1 to it each time? )
       
      For $i = 1 To UBound($hash) - 500 ; LIke that ^ For $i = 500 To UBound($hash) - 500 ; or like this^ Thanks a lot.