Jump to content

Progress time decreasing?


Recommended Posts

Hi all.

I wunder if anyone could help me with a thing i have coded.

I just wunder why my code is keep decreasing the time before it is done (it only decrease the time if there is no action on the GUI from the user), why?

I have tryed to find a topic with a problem like this, but i could not find any, so i desired to whrite one:

#include <GUIConstants.au3>

GUICreate("something",390,280)
WinSetOnTop("something", "", 0)
$button = GUICtrlCreateButton ("Start",9,190,91,40)
$button2 = GUICtrlCreateButton ("Stop",100,190,91,40)


$Input_Where = GuiCtrlCreateLabel("100", 130, 140, 50, 20)


;SHOW GUI
GUISetState(@SW_SHOW)


$ConstantTime = 100


While 1
    $msg = GUIGetMsg()
    $TimerMinus = $ConstantTime
    $TimerPlus = $TimerMinus - 1
Call("Quit")
If $msg = $button Then
$begin = TimerInit()
Do
    $msg = GUIGetMsg()  ; if this...

    If $msg = $button2 Then; ...and this is off the timer will be ok!?
    GUICtrlSetData ($Input_Where, $ConstantTime)
    ExitLoop                
    EndIf                   




; >>> something here to fix the timer??? <<<


Call("Quit")
GUICtrlSetData ($Input_Where, $TimerMinus)
Call("TIMER")

Until $TimerMinus = 0
$dif = TimerDiff($begin)
MsgBox(0,"Time Difference",$dif)
EndIf
WEnd

;=timer===================
Func TIMER()
$TimerMinus = $TimerMinus - 1
If $TimerMinus = $TimerPlus Then
    sleep(40)
EndIf
$TimerPlus = $TimerPlus - 1
EndFunc
;=timer===================

Func Quit()
    If $msg = $GUI_EVENT_CLOSE Then
    Exit
    EndIf
EndFunc

;known bugs:
;The timer is adding @ 1 sec if the mouse is not moving over the GUI while it is in progress(it decressing the time if no action on the GUI)

Please bare with me, im new and this is my first script and my first topic :)

Thanks.

Link to comment
Share on other sites

a quick look i noticed this

While 1
    $msg = GUIGetMsg()
    $TimerMinus = $ConstantTime
    $TimerPlus = $TimerMinus - 1

when the GUI has nothing to do, its going over $TimerPlus = $TimerMinus - 1 i would *almost* bet thats your problem area right their :)

Link to comment
Share on other sites

Thx for your reply, 4gotn1.

I have tryed to config the timer in several ways, but no luck.

I dont think that it is the problem cuz when the timer is on, it only uses the code within 'Do-Untill' (Would i guess).

I think the problem is within the 'Do-Untill'.

BTW if i remove:

$msg = GUIGetMsg()  ; if this...

    If $msg = $button2 Then; ...and this is off the timer will be ok!?
    GUICtrlSetData ($Input_Where, $ConstantTime)
    ExitLoop                
    EndIf

then there is no problem, but i need it in my code.

:)

Link to comment
Share on other sites

Thx for your reply, 4gotn1.

I have tryed to config the timer in several ways, but no luck.

I dont think that it is the problem cuz when the timer is on, it only uses the code within 'Do-Untill' (Would i guess).

I think the problem is within the 'Do-Untill'.

BTW if i remove:

$msg = GUIGetMsg(); if this...

    If $msg = $button2 Then; ...and this is off the timer will be ok!?
    GUICtrlSetData ($Input_Where, $ConstantTime)
    ExitLoop                
    EndIf

then there is no problem, but i need it in my code.

:)

From looking at just that code, why do you have an ExitLoop there?
Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite
Link to comment
Share on other sites

From looking at just that code, why do you have an ExitLoop there?

Thx for your reply, JoshDB.

Because it will be called when i hit the 'Stop' button in the GUI.

It will then exit the 'Do-Until' -loop and enter 'While-Wend' -loop again.

Link to comment
Share on other sites

Never mind, guys.

I got it fixed by using 'Opt("GUIOnEventMode", 1)' .

If anyone have has the same problem, then here is how i fixed it:

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)


$time = 0
$time_reset = 0

$activated = 0

$Main_Window = GUICreate("something", 390,280)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_EVENT_CLOSE")

$button_start = GUICtrlCreateButton("Start", 9,190,91,40)
GUICtrlSetOnEvent($button_start, "button_start")

$button_stop = GUICtrlCreateButton ("Stop",100,190,91,40)
GUICtrlSetOnEvent($button_stop, "button_stop")

$label_where = GuiCtrlCreateLabel($time, 130, 140, 50, 20)
GuiCtrlCreateLabel("%", 150, 140, 50, 20)

$progressbar = GUICtrlCreateProgress (10,230,180,40)



GUISetState(@SW_SHOW)

While 1
If $activated = 1 Then
$time = $time + 1
GUICtrlSetData($label_where,$time)
GUICtrlSetData($progressbar,$time)
EndIf

If $time = 0 Then
$begin = TimerInit()
EndIf

If $time = 100 Then
$dif = TimerDiff($begin)
MsgBox(0,"Time Difference",$dif)
$activated = 0; stops the timer from repeating
$time = $time_reset
GUICtrlSetData($label_where,$time_reset)
GUICtrlSetData($progressbar,$time_reset)
EndIf

Sleep(40)
WEnd

Func button_start()
$activated = 1
EndFunc

Func button_stop()
$activated = 0
$time = $time_reset
GUICtrlSetData($label_where,$time_reset)
GUICtrlSetData($progressbar,$time_reset)
EndFunc

Func GUI_EVENT_CLOSE()
Exit
EndFunc

Then you can get a idea on how to fix yours, if you have the same problem.

BTW, thx for the replys.

:)

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...