Sign in to follow this  
Followers 0
Iemoniscool

multiple countdowns?

12 posts in this topic

Hi!

Im trying to programm a tool which counts down several times.

my problem is, i need to start 8 countdowns at a time.

anyone knows how i can do that?

here is my code

Func timer_1()
    $time_1 = GUICtrlRead($Input9)
    _CountDown("0",$time_1, "", "", True, $Label1)
EndFunc

Func timer_2()
    $time_2 = GUICtrlRead($Input10)
    _CountDown("0",$time_2, "", "", True, $Label2)
EndFunc

Im Using this countdown script

#include <Date.au3>
Func _CountDown($SEC, $MIN=0, $HOUR=0, $DAY=0, $VISIBLEDOWN=True, $ALTERNATECTRL='TT')
    $Sekunden = $SEC + $MIN*60 + $HOUR*3600 + $DAY*86400
    $end = _DateAdd('s', $Sekunden, _NowCalc())
    Local $message
    Do
        Sleep(100)
        $sec = _DateDiff('s', _NowCalc(), $end)
        If Not $VISIBLEDOWN Then 
            $secShow = $Sekunden - $sec
        Else
            $secShow = $sec
        EndIf
        Select
            Case $secShow < 60
                If $ALTERNATECTRL = 'TT' Then
                    ToolTip(StringFormat('%02u', $secShow) & ' s')
                Else
                    GUICtrlSetData($ALTERNATECTRL, StringFormat('%02u', $secShow) & ' s')
                EndIf
            Case $secShow < 60*60
                $message = StringFormat('%02u', Floor($secShow/60)) & ':' & _
                            StringFormat('%02u', Mod($secShow,60)) & ' min'
                If $ALTERNATECTRL = 'TT' Then
                    ToolTip($message)
                Else
                    GUICtrlSetData($ALTERNATECTRL, $message)
                EndIf
            Case $secShow < 60*60*24
                $message = StringFormat('%02u', Floor($secShow/3600)) & ':' & _
                            StringFormat('%02u', Floor(Mod($secShow,3600)/60)) & ':' & _
                            StringFormat('%02u', Mod(Mod($secShow,3600),60)) & ' h'
                If $ALTERNATECTRL = 'TT' Then
                    ToolTip($message)
                Else
                    GUICtrlSetData($ALTERNATECTRL, $message)
                EndIf
            Case Else
                $message = Floor($secShow/86400) & ' d / ' & _
                            StringFormat('%02u', Floor(Mod($secShow,86400)/3600)) & ':' & _
                            StringFormat('%02u', Floor(Mod(Mod($secShow,86400),3600)/60)) & ':' & _
                            StringFormat('%02u', Mod(Mod(Mod($secShow,86400),3600),60)) & ' h'
                If $ALTERNATECTRL = 'TT' Then
                    ToolTip($message)
                Else
                    GUICtrlSetData($ALTERNATECTRL, $message)
                EndIf
        EndSelect
    Until $sec = 0
EndFunc

Thanks in advance

lemoniscool

Share this post


Link to post
Share on other sites



Execute("_CountDown('0', " & Eval("timer_" & $i) & ", '', '', True, " & Eval('Label' & $i))

You can do yourself a favor and use only arrays because it'll make your script much simpler and readable.

Share this post


Link to post
Share on other sites

umm .. could you please explain it a bit more? i never used this command and im not really familiar to arrays...

Share this post


Link to post
Share on other sites

Let say you have $i variable as counter or subscript element of the specific variable like: $Timer_? now '?' can be any allowed range that $i might contain like from 0 to 9 if you got $Timer_0...$Timer...4...$Timer_9 (10 variables) so you're just evaluating the variable which concatenating with $i results in a valid variable name. Confused? lol me too.

Dim $i = 3

Dim $Dum_1 = 44, $Dum_2 = 55, $Dum_3 = 99

Dim $Result = Eval('Dum_' & $i) ; $Result now contains 99

$i -= 2

$Result = Eval('Dum_' & $i) ; $Result now contains 44

.

.

.

And so on.

Execute does quite the same by interpreting the resulting string and executing it if it's logical.

Func _First($Res)
    Return $Res+10
EndFunc

Dim $Result = Execute('_Firs' & 't(444)')
MsgBox(0x10, 'Title', $Result)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

okay .. think i understood now, but .. i only think xD

umm but i think this is not what i wanted ..

see .. lets say my GUI looks anyhow like this:

[Label to show the 1st countdown] [input for the time in minutes to count down] [start button] [pause button]

[Label to show the 2nd countdown] [input for the time in minutes to count down] [start button] [pause button]

...

[Label to show the 8th countdown] [input for the time in minutes to count down] [start button] [pause button]

now i type in some times..

[Label to show the 1st countdown] [20 minutes] [start button] [pause button]

[Label to show the 2nd countdown] [30 minutes] [start button] [pause button]

and press the start buttons after that .. now the program should count down both times in real time... how to show the time in the labels isnt the problem thats easy xD and to handle one countdown works too .. but when i start the first countdown i cant do anything until it is finished, i cant even exit the program normally .. think thats because i used a do..until-loop... know what i mean?

if u didnt understand me, i can upload my script files so you can see what i mean xDD

greetz lemoniscool

Edited by Iemoniscool

Share this post


Link to post
Share on other sites

TimerInit ; TimerDiff ?

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

pfff... So you want multithreading your script? too bad because you can't. Your script can execute only a single statement at a time, meaning that if you use AdlibEnable(), your script is interrupted where it was until the AdlibEnable UDF is done executing it's code.

Share this post


Link to post
Share on other sites

Seemed like a fun one to play with for practice:

#include <GuiConstantsEx.au3>
#include <Array.au3>

Opt("GuiOnEventMode", 1)

; $avTimers:
;   [0][0] = count
;   [n][0] = input control
;   [n][1] = start/stop button
;   [n][2] = timer (0 = not running)
Global $avTimers[1][3] = [[0, "", ""]]

Global $hGUI, $iCount, $iTimer, $iDisplay

$iCount = Int(InputBox("Timers", "Number of timers: "))
If $iCount < 1 Then 
    Exit
Else
    ReDim $avTimers[$iCount + 1][UBound($avTimers, 2)]
    $avTimers[0][0] = $iCount
EndIf

$hGUI = GUICreate("Timers", 260, 20 + ($iCount * 40))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
For $n = 1 To $iCount
    $avTimers[$n][0] = GUICtrlCreateInput("0", 20, ($n * 40) - 20, 100, 20)
    $avTimers[$n][1] = GUICtrlCreateButton("Start", 140, ($n * 40) - 20, 100, 20)
    GUICtrlSetOnEvent(-1, "_ButtonHit")
    $avTimers[$n][2] = 0
Next
GUISetState()

While 1
    Sleep(100)
    ; Update timers
    For $n = 1 To $iCount
        If $avTimers[$n][2] Then
            $iDisplay = Int(ControlGetText($hGUI, "", $avTimers[$n][0]))
            $iTimer = Int(TimerDiff($avTimers[$n][2]) / 1000)
            If $iTimer >= 1 Then 
                $iNewDisplay = $iDisplay + $iTimer
                If $iNewDisplay = 0 Then
                    ; Stop
                    $avTimers[$n][2] = 0 
                    ControlSetText($hGUI, "", $avTimers[$n][1], "Start")
                    Beep(2000, 250)
                Else
                    $avTimers[$n][2] = TimerInit()
                EndIf
                ControlSetText($hGUI, "", $avTimers[$n][0], $iNewDisplay)
            EndIf
        EndIf
    Next
WEnd

Func _ButtonHit()
    Local $iButton, $iIndex, $sText
    
    $iButton = @GUI_CtrlId
    $sText = ControlGetText($hGUI, "", $iButton)
    $iIndex = _ArraySearch($avTimers, $iButton, 1, 0, 0, 0, 1, 1)
    If @error Then 
        MsgBox(16, "Error", "Failed to find button control ID")
        Return
    EndIf
    
    If $sText = "Start" Then
        ; Start counter
        $avTimers[$iIndex][2] = TimerInit()
        ControlSetText($hGUI, "", $iButton, "Stop")
    Else
        ; Stop counter
        $avTimers[$iIndex][2] = 0
        ControlSetText($hGUI, "", $iButton, "Start")
    EndIf
EndFunc

Func _Quit()
    Exit
EndFunc

Always counts up. Set a negative time and it will beep and stop at 0.

:)


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

Share this post


Link to post
Share on other sites

psalty!

hmm this request looks very similar to mine! mine is pretty different bc it has child windows and labels but ive still been trying to get it working like you got it working here..

no luck

what am i doing wrong???

#642371

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

okay .. im in school now xD

thanks psalty, ill try it when im at home, this looks good ... mayber ill understand arrays now xD

greetz

lemoniscool

//EDIT

okay got some time now xDD

this is cool, but i get an error when i want to start a countdown ...

"Incorrect number of parameters in function call"

ill try to fix myself but wanted to mention this ^^

Edited by Iemoniscool

Share this post


Link to post
Share on other sites

@psalty..

Wow man.. u rock.. what an awesome way to get it done.. i cudn't find a way to get around the problem of multiple threading.. but u made it vanish with a flick.. indeed u r most venerable..

salutations from me..


[font="Garamond"]Manjish Naik[/font]Engineer, Global Services - QPSHoneywell Automation India LimitedE-mail - Manjish.Naik@honeywell.com

Share this post


Link to post
Share on other sites

hi me again .. im at home now and .. im sry xD there is no error in this script .. anyhow the pc in school didnt want to run it xD

this script is awesome thanks psalty =)

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