Sign in to follow this  
Followers 0
yousefsamy

i want to make a timer here how !!

9 posts in this topic

i try 2 codes : _guitooltip_settimedelay    and   _timer_settimer   <== but i got no result

here is my code  :sweating:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiToolTip.au3>
#include <Timers.au3>


$Form1 = GUICreate("Form1", 355, 202, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 48, 16, 225, 21)
$Button1 = GUICtrlCreateButton("Button1", 80, 64, 161, 81)

GUISetState(@SW_SHOW)


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

        Case $Button1 ;Here i want to pop up my msg after the duration i want how !!
            $t = GUICtrlRead($Input1)
            _Timer_SetTimer( MsgBox(0,"","") , $t * 1000 )




    EndSwitch
WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This might not be the best approach, but it works (i'm sure there are many ways of doing it - that's the magic of autoit):

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $timer, $tdiff, $t, $timeron = 0 ;add some global variables for ease of tracking
$Form1 = GUICreate("Form1", 355, 202, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 48, 16, 225, 21)
$Button1 = GUICtrlCreateButton("Button1", 80, 64, 161, 81)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;Here i want to pop up my msg after the duration i want how !!
            $t = GUICtrlRead($Input1)
            $timeron = 1                    ;set $timeron to 1 so that we can start checking timer elapsed time in the While loop below
            $timer = TimerInit()            ;initiate a timer and assign to $timer variable
    EndSwitch
    If $timeron = 1 Then                    ;if $timeron is 1 then we can start checking the elapsed timer time
        $tdiff = TimerDiff($timer)          ;$tdiff = time in milliseconds that has passed since we started our timer above using TimerInit()
        If $tdiff >= 2000 Then              ;if the timer reaches 2000 milliseconds (2 seconds) or more then we pop up a message box - we can even report how much time has passed since we started the timer by adding $tdiff to the MsgBox
            MsgBox(0,'','Your text was: ' & $t & @CRLF & @CRLF & 'This message popped up after ' & Round($tdiff/1000, 2) & ' seconds.') ;pop up the message
            $timeron = 0                    ;set $timeron to 0 so that we stop checking for timer until we start it again by clicking the button :)
        EndIf
    EndIf
WEnd

Edit: Whoops I didn't notice you wanted to get seconds value from the input, so here is a modified script that does that. 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $timer, $tdiff, $t, $timeron = 0 ;add some global variables for ease of tracking
$Form1 = GUICreate("Form1", 355, 202, 192, 124)
$Input1 = GUICtrlCreateInput("Enter duration in seconds here", 48, 16, 225, 21)
$Button1 = GUICtrlCreateButton("Button1", 80, 64, 161, 81)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;Here i want to pop up my msg after the duration i want how !!
            $t = GUICtrlRead($Input1)
            $timeron = 1                    ;set $timeron to 1 so that we can start checking timer elapsed time in the While loop below
            $timer = TimerInit()            ;initiate a timer and assign to $timer variable
    EndSwitch
    If $timeron = 1 Then                    ;if $timeron is 1 then we can start checking the elapsed timer time
        $tdiff = TimerDiff($timer)          ;$tdiff = time in milliseconds that has passed since we started our timer above using TimerInit()
        If $tdiff >= $t * 1000 Then         ;if the timer reaches set time in seconds or more then we pop up a message box - we can even report how much time has passed since we started the timer by adding $tdiff to the MsgBox
            MsgBox(0,'','You set timer to: ' & $t & ' seconds.' & @CRLF & @CRLF & 'This message popped up after ' & Round($tdiff/1000, 0) & ' seconds.') ;pop up the message
            $timeron = 0                    ;set $timeron to 0 so that we stop checking for timer until we start it again by clicking the button :)
        EndIf
    EndIf
WEnd

The difference between my script and the one posted below by somdcomputerguy is that with my script you can have other things happening at the same time. e.g. have another button that you can click and get a different message, whilst the timer is running (or not).  See Example below:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $timer, $tdiff, $t, $timeron = 0 ;add some global variables for ease of tracking
$Form1 = GUICreate("Form1", 355, 202, 192, 124)
$Input1 = GUICtrlCreateInput("Enter duration in seconds here", 48, 16, 225, 21)
$Button1 = GUICtrlCreateButton("Button1", 80, 64, 100, 50)
$Button2 = GUICtrlCreateButton("Button2", 80, 124, 100, 50)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;Here i want to pop up my msg after the duration i want how !!
            $t = GUICtrlRead($Input1)
            $timeron = 1                    ;set $timeron to 1 so that we can start checking timer elapsed time in the While loop below
            $timer = TimerInit()            ;initiate a timer and assign to $timer variable
        Case $Button2
            If $timeron = 1 Then
                MsgBox(0,'','You pressed Button2 whilst time was ON')
            Else
                MsgBox(0,'','You pressed Button2 whilst time was OFF')
            EndIf
    EndSwitch
    If $timeron = 1 Then                    ;if $timeron is 1 then we can start checking the elapsed timer time
        $tdiff = TimerDiff($timer)          ;$tdiff = time in milliseconds that has passed since we started our timer above using TimerInit()
        If $tdiff >= $t * 1000 Then         ;if the timer reaches set time in seconds or more then we pop up a message box - we can even report how much time has passed since we started the timer by adding $tdiff to the MsgBox
            MsgBox(0,'','You set timer to: ' & $t & ' seconds.' & @CRLF & @CRLF & 'This message popped up after ' & Round($tdiff/1000, 0) & ' seconds.') ;pop up the message
            $timeron = 0                    ;set $timeron to 0 so that we stop checking for timer until we start it again by clicking the button :)
        EndIf
    EndIf
WEnd

With somdcomputerguy's script even if you have a second button that pops up another message box it will only pop after the first message box is gone (i.e. each button's action will be queued and will fire only after the first one is done). I guess it all comes down to how you want to handle this for your particular application - I prefer to be able to execute concurrent action to provide a seamless user experience, but I can see where Sleep(x) can come in handy.

Edited by mpower
1 person likes this

Share this post


Link to post
Share on other sites

Here is a modified version of the code you posted.

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("Form1", 355, 202, 192, 124)
$Input1 = GUICtrlCreateInput("Enter # of seconds to wait..", 48, 16, 225, 21)
$Button1 = GUICtrlCreateButton("Button1", 80, 64, 161, 81)

GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1 ;Here i want to pop up my msg after the duration i want how !!
$t = GUICtrlRead($Input1)
Sleep($t * 1000 )
MsgBox(0, $t, "This dialog popped up after " & $t & " seconds")
EndSwitch
WEnd
1 person likes this

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

Here is a modified version of the code you posted.

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("Form1", 355, 202, 192, 124)
$Input1 = GUICtrlCreateInput("Enter # of seconds to wait..", 48, 16, 225, 21)
$Button1 = GUICtrlCreateButton("Button1", 80, 64, 161, 81)

GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1 ;Here i want to pop up my msg after the duration i want how !!
$t = GUICtrlRead($Input1)
Sleep($t * 1000 )
MsgBox(0, $t, "This dialog popped up after " & $t & " seconds")
EndSwitch
WEnd

 

really bro i got this idea but cant use this code timer_settimer <=== ??

Share this post


Link to post
Share on other sites

This might not be the best approach, but it works (i'm sure there are many ways of doing it - that's the magic of autoit):

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $timer, $tdiff, $t, $timeron = 0 ;add some global variables for ease of tracking
$Form1 = GUICreate("Form1", 355, 202, 192, 124)
$Input1 = GUICtrlCreateInput("Input1", 48, 16, 225, 21)
$Button1 = GUICtrlCreateButton("Button1", 80, 64, 161, 81)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;Here i want to pop up my msg after the duration i want how !!
            $t = GUICtrlRead($Input1)
            $timeron = 1                    ;set $timeron to 1 so that we can start checking timer elapsed time in the While loop below
            $timer = TimerInit()            ;initiate a timer and assign to $timer variable
    EndSwitch
    If $timeron = 1 Then                    ;if $timeron is 1 then we can start checking the elapsed timer time
        $tdiff = TimerDiff($timer)          ;$tdiff = time in milliseconds that has passed since we started our timer above using TimerInit()
        If $tdiff >= 2000 Then              ;if the timer reaches 2000 milliseconds (2 seconds) or more then we pop up a message box - we can even report how much time has passed since we started the timer by adding $tdiff to the MsgBox
            MsgBox(0,'','Your text was: ' & $t & @CRLF & @CRLF & 'This message popped up after ' & Round($tdiff/1000, 2) & ' seconds.') ;pop up the message
            $timeron = 0                    ;set $timeron to 0 so that we stop checking for timer until we start it again by clicking the button :)
        EndIf
    EndIf
WEnd

Edit: Whoops I didn't notice you wanted to get seconds value from the input, so here is a modified script that does that. 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $timer, $tdiff, $t, $timeron = 0 ;add some global variables for ease of tracking
$Form1 = GUICreate("Form1", 355, 202, 192, 124)
$Input1 = GUICtrlCreateInput("Enter duration in seconds here", 48, 16, 225, 21)
$Button1 = GUICtrlCreateButton("Button1", 80, 64, 161, 81)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;Here i want to pop up my msg after the duration i want how !!
            $t = GUICtrlRead($Input1)
            $timeron = 1                    ;set $timeron to 1 so that we can start checking timer elapsed time in the While loop below
            $timer = TimerInit()            ;initiate a timer and assign to $timer variable
    EndSwitch
    If $timeron = 1 Then                    ;if $timeron is 1 then we can start checking the elapsed timer time
        $tdiff = TimerDiff($timer)          ;$tdiff = time in milliseconds that has passed since we started our timer above using TimerInit()
        If $tdiff >= $t * 1000 Then         ;if the timer reaches set time in seconds or more then we pop up a message box - we can even report how much time has passed since we started the timer by adding $tdiff to the MsgBox
            MsgBox(0,'','You set timer to: ' & $t & ' seconds.' & @CRLF & @CRLF & 'This message popped up after ' & Round($tdiff/1000, 0) & ' seconds.') ;pop up the message
            $timeron = 0                    ;set $timeron to 0 so that we stop checking for timer until we start it again by clicking the button :)
        EndIf
    EndIf
WEnd

The difference between my script and the one posted below by somdcomputerguy is that with my script you can have other things happening at the same time. e.g. have another button that you can click and get a different message, whilst the timer is running (or not).  See Example below:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Global $timer, $tdiff, $t, $timeron = 0 ;add some global variables for ease of tracking
$Form1 = GUICreate("Form1", 355, 202, 192, 124)
$Input1 = GUICtrlCreateInput("Enter duration in seconds here", 48, 16, 225, 21)
$Button1 = GUICtrlCreateButton("Button1", 80, 64, 100, 50)
$Button2 = GUICtrlCreateButton("Button2", 80, 124, 100, 50)

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1 ;Here i want to pop up my msg after the duration i want how !!
            $t = GUICtrlRead($Input1)
            $timeron = 1                    ;set $timeron to 1 so that we can start checking timer elapsed time in the While loop below
            $timer = TimerInit()            ;initiate a timer and assign to $timer variable
        Case $Button2
            If $timeron = 1 Then
                MsgBox(0,'','You pressed Button2 whilst time was ON')
            Else
                MsgBox(0,'','You pressed Button2 whilst time was OFF')
            EndIf
    EndSwitch
    If $timeron = 1 Then                    ;if $timeron is 1 then we can start checking the elapsed timer time
        $tdiff = TimerDiff($timer)          ;$tdiff = time in milliseconds that has passed since we started our timer above using TimerInit()
        If $tdiff >= $t * 1000 Then         ;if the timer reaches set time in seconds or more then we pop up a message box - we can even report how much time has passed since we started the timer by adding $tdiff to the MsgBox
            MsgBox(0,'','You set timer to: ' & $t & ' seconds.' & @CRLF & @CRLF & 'This message popped up after ' & Round($tdiff/1000, 0) & ' seconds.') ;pop up the message
            $timeron = 0                    ;set $timeron to 0 so that we stop checking for timer until we start it again by clicking the button :)
        EndIf
    EndIf
WEnd

With somdcomputerguy's script even if you have a second button that pops up another message box it will only pop after the first message box is gone (i.e. each button's action will be queued and will fire only after the first one is done). I guess it all comes down to how you want to handle this for your particular application - I prefer to be able to execute concurrent action to provide a seamless user experience, but I can see where Sleep(x) can come in handy.

 

My Bro,, Thnx alot

i want to be very simple in my codes ,, i think this is the right way in programming

Share this post


Link to post
Share on other sites

yousefsamy,

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - we know what we wrote and it just pads the thread unnecessarily. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

oh okay  :sweating:

Share this post


Link to post
Share on other sites

yousefsamy,

Thanks. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Not at all ,, Dear..

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