Jump to content

Whats wrong with this timer? (Solved)


Recommended Posts

Hey, Im trying to learn how this works. What is wrong with what I have written here?

#Include <Timers.au3>

$hWnd = GUICreate("Window", 500, 700, Default, Default)
GUISetState(@SW_SHOW)
_Timer_SetTimer($hWnd, 3000, "somefunc", -1)

While 1 
    Sleep(10)
WEnd

Func somefunc()
Msgbox(0,"","Working")
EndFunc
Edited by Hatcheda
Link to comment
Share on other sites

  • Moderators

Hatcheda,

You need to add the parameters to the function - just like in GUIRegisterMsg:

#Include <Timers.au3>

$hWnd = GUICreate("Window", 500, 700, Default, Default)
GUISetState(@SW_SHOW)
_Timer_SetTimer($hWnd, 3000, "somefunc", -1)

While 1 
    Sleep(10)
WEnd

Func somefunc($hWnd, $iMsg, $iwParam, $ilParam)
Msgbox(0,"","Working")
EndFunc

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

ok, based on that, is there any info from the timer that could be used to identify it? Purpose being the function would be a switch and behave differently if a 3 second timer called it than a 6 second timer.

#Include <Timers.au3>

$hWnd = GUICreate("Window", 500, 700, Default, Default)
GUISetState(@SW_SHOW)
_Timer_SetTimer($hWnd, 3000, "somefunc", -1)
_Timer_SetTimer($hWnd, 6000, "somefunc", -1)

While 1
    Sleep(10)
WEnd

Func somefunc($hWnd, $iMsg, $iwParam, $ilParam)
Msgbox(0,"","Working")
EndFunc
Link to comment
Share on other sites

  • Moderators

Hatcheda,

From that same Help file that showed the need for parameters:

_Timer_GetTimerID - Returns the Timer ID from $iwParam

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Sorry, was testing them all out. I was only up to $iMsg when I asked that

#Include <Timers.au3>
HotKeySet("{ESC}", "TerminateApp")

$hWnd = GUICreate("Window", 500, 700, Default, Default)
GUISetState(@SW_SHOW)
_Timer_SetTimer($hWnd, 3000, "somefunc", -1)
_Timer_SetTimer($hWnd, 6000, "somefunc", -1)

While 1
    Sleep(10)
WEnd

Func somefunc($hWnd, $iMsg, $iwParam, $ilParam)

Msgbox(0,"","Working" & $iMsg & " " & $iwParam & " " & $ilParam)
EndFunc


Func TerminateApp()
_Timer_KillAllTimers($hWnd)
    GUIDelete()
    Exit 0
EndFunc  ;==>TerminateApp
Link to comment
Share on other sites

Ok, Here ya go! Completed as demo -now I can use it in my scripts.

#include <Timers.au3>
HotKeySet("{ESC}", "TerminateApp")

$hWnd = GUICreate("Window", 500, 700, Default, Default)
GUISetState(@SW_SHOW)
_Timer_SetTimer($hWnd, 3000, "somefunc", -1)
_Timer_SetTimer($hWnd, 6000, "somefunc", -1)
_Timer_SetTimer($hWnd, 9000, "somefunc", -1)

While 1
    Sleep(10)
WEnd

Func somefunc($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case 1001
            MsgBox(0, "", "3Sec")
        Case 1002
            MsgBox(0, "", "6Sec")
        Case 1003
            MsgBox(0, "", "9Sec")
    EndSwitch
EndFunc   ;==>somefunc

Func TerminateApp()
    _Timer_KillAllTimers($hWnd)
    GUIDelete()
    Exit 0
EndFunc   ;==>TerminateApp
Link to comment
Share on other sites

  • Moderators

Hatcheda,

It would be even better if you were to save the ControlIDs of the timers and use those variables in the Switch: ;-)

#include <Timers.au3>
HotKeySet("{ESC}", "TerminateApp")

$hWnd = GUICreate("Window", 500, 700, Default, Default)
GUISetState(@SW_SHOW)
$hTimer1 = _Timer_SetTimer($hWnd, 3000, "somefunc", -1)
$hTimer2 = _Timer_SetTimer($hWnd, 6000, "somefunc", -1)
$hTimer3 = _Timer_SetTimer($hWnd, 9000, "somefunc", -1)

While 1
    Sleep(10)
WEnd

Func somefunc($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case $hTimer1
            MsgBox(0, "", "3Sec")
        Case $hTimer2
            MsgBox(0, "", "6Sec")
        Case $hTimer3
            MsgBox(0, "", "9Sec")
    EndSwitch
EndFunc  ;==>somefunc

Func TerminateApp()
    _Timer_KillAllTimers($hWnd)
    GUIDelete()
    Exit 0
EndFunc  ;==>TerminateApp

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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