Jump to content

Progress bar help


Recommended Posts

OK I am trying to create a progress bar to last 60 sec ( 1 min)

I took the example and here is what I did.

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $progressbar1, $progressbar2, $button, $wait, $s, $msg, $m
    
    GUICreate("My GUI Progressbar", 220, 100, 100, 200)
    $progressbar1 = GUICtrlCreateProgress(10, 10, 200, 20)
    GUICtrlSetColor(-1, 32250); not working with Windows XP Style
    $progressbar2 = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
    $button = GUICtrlCreateButton("Start", 75, 70, 70, 20)
    GUISetState()

    $wait = 10; wait 20ms for next progressstep
    $s = 0; progressbar-saveposition
    Do
        $msg = GUIGetMsg()
        If $msg = $button Then
            GUICtrlSetData($button, "Stop")
            For $i = $s To 60000
                If GUICtrlRead($progressbar1) = 30000 Then MsgBox(0, "Info", "The half is done...", 1)
                $m = GUIGetMsg()
                
                If $m = -3 Then ExitLoop
                
                If $m = $button Then
                    GUICtrlSetData($button, "Next")
                    $s = $i;save the current bar-position to $s
                    ExitLoop
                Else
                    $s = 0
                    GUICtrlSetData($progressbar1, $i)
                    GUICtrlSetData($progressbar2, (60000 - $i))
                    Sleep($wait)
                EndIf
            Next
            If $i > 60000 Then
                ;       $s=0
                GUICtrlSetData($button, "Start")
            EndIf
        EndIf
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Thought I had it. Problem Is, it just zooms right through the progress bar. I want 60 sec and it completes in 1 sec. lol

Oh the agony of an autoit noob. lol

Any ideas?

Thanks in advance

Cue

Link to comment
Share on other sites

Data to a ProgressBar is in percentage. Re-read help file > GUICtrlSetData > Data parameter for Progress: percentage.

Of course 60000% is infinitely close to the right end :(

You can dissociate your main code and the update of the progress bar this way:

#include <ProgressConstants.au3>

Global $pb1Duration
Global $pb1Step
Global $pb1Timer

GUICreate("My GUI Progressbar", 220, 100, 100, 200)
Global $progressbar1 = GUICtrlCreateProgress(10, 10, 200, 20, $PBS_SMOOTH)
GUISetState()

; when you want to start
GUICtrlSetData($progressbar1, 20)
$pb1Duration = 60000                        ; duration is 60s
$pb1Step = 200                              ; update every 200ms
$pb1Timer = 0                               ; initial value = 0
AdlibRegister("_UpdateProgress", $pb1Step);

; you can do something else here
For $i = 0 To 65
    ConsoleWrite("Serious, I've been working hard for " & $i & " seconds!" & @LF)
    Sleep(1000)
Next

; don't forget to unregister the update function!       <----------------------
AdlibUnRegister("_UpdateProgress");

Func _UpdateProgress()
    If $pb1Timer < $pb1Duration Then        ; update only if meaningful
        $pb1Timer += $pb1Step + 0.0
        GUICtrlSetData($progressbar1, 100 * $pb1Timer / $pb1Duration)
    EndIf
EndFunc
Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

I have 1 other question... I noticed the function in there and that you can not wrap a function in a function, so how would i go about calling this progress bar once a button is clicked?

Thanks in advance

Cue

Link to comment
Share on other sites

I have 1 other question... I noticed the function in there and that you can not wrap a function in a function, so how would i go about calling this progress bar once a button is clicked?

You can make a call to another function from inside a function. You just can't DECLARE one function inside another.

Bad (attempt to declare _FunctionTwo inside _FunctionOne):

Func _FunctionOne()

     _FunctionTwo() ; Call the other function

     Func _FunctionTwo()

          ; ...

     EndFunc

EndFunc

Good (both functions are declared, _FunctionTwo is called from inside _FunctionOne):

Func _FunctionOne()

     _FunctionTwo() ; Call the other function

EndFunc

Func _FunctionTwo()

     ; ...

EndFunc

:(

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Here's how you can launch the progress bar function when you want.

#include <ProgressConstants.au3>

Global $pb1Duration
Global $pb1Step
Global $pb1Timer

GUICreate("My GUI Progressbar", 220, 100, 100, 200)
Global $progressbar1 = GUICtrlCreateProgress(10, 10, 200, 20, $PBS_SMOOTH)
GUISetState()

; say it's your main function, where you put your applicative code
; you call it once here
mainCode()

; place applicative code here
Func mainCode()
    Local $time = TimerInit()
    ConsoleWrite("Hi " & @UserName & ", how are you?" & @LF)
    For $i = 0 To 65
        ConsoleWrite(StringFormat("This sample application has been running for about %.2f seconds\n", TimerDiff($time)/1000.))
        ConsoleWrite("It is now " & _Now() & @LF)
        Sleep(Random(500, 5000, 1))
        If $i = 4 Then LaunchProgressBar()      ;; progress bar will start progressin by itself at the 4th iteration
    Next
EndFunc

; invoke when you want to start
Func LaunchProgressBar()
    GUICtrlSetData($progressbar1, 0)
    $pb1Duration = 60000    ; duration is 60s
    $pb1Step = 200  ; update every 200ms
    $pb1Timer = 0   ; initial value = 0
    AdlibRegister("_UpdateProgress", $pb1Step);
EndFunc

Func _UpdateProgress()
    If $pb1Timer < $pb1Duration Then    ; update only if meaningful
    $pb1Timer += $pb1Step + 0.0
    GUICtrlSetData($progressbar1, 100 * $pb1Timer / $pb1Duration)
    Else
        AdlibUnRegister("_UpdateProgress");
    EndIf
EndFunc

Geez, again taken over by a penguin!

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...