Jump to content

msgbox when clock time = specified time


Go to solution Solved by Melba23,

Recommended Posts

Posted

hi all

what i'm trying to accomplish is a small script that give a msgbox when the clock time equals the time the user provide in the GUI

but it won't work until the user press the button

here is what i tried 

#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <date.au3>


    GUICreate("My GUI get date", 200, 200, 800, 200)
    $date = GUICtrlCreateDate("", 10, 10, 185, 20)
    $button = GUICtrlCreateButton("", 50, 50, 100, 50)

    ; to select a specific default format
    $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW
    $style = "M/d/yyyy hh:mm:ss tt"
    GUICtrlSendMsg($date, $DTM_SETFORMAT_, 0, $style)

    GUISetState()

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then Exit
    if $nMsg = $button then but()
WEnd

func but()
    do
    Sleep (1000)
    Until _Now() = GUICtrlRead($date)
    MsgBox(0, "", "matched")
EndFunc

any ideas why this wont work for me ?

  • Moderators
  • Solution
Posted

alexander95,

 

  Quote

any ideas why this wont work for me ?

Yes. Try adding these 2 lines and see if you can see it as well: ;)

func but()

    ConsoleWrite(GUICtrlRead($date) & @CRLF)
    ConsoleWrite(_Now() & @CRLF)

    do
    Sleep (1000)
    Until _Now() = GUICtrlRead($date)
    MsgBox(0, "", "matched")
EndFunc
Did the light bulb illuminate? :)

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:

  Reveal hidden contents

 

Posted

  On 8/27/2013 at 12:59 PM, Melba23 said:

alexander95,

 

Yes. Try adding these 2 lines and see if you can see it as well: ;)

func but()

    ConsoleWrite(GUICtrlRead($date) & @CRLF)
    ConsoleWrite(_Now() & @CRLF)

    do
    Sleep (1000)
    Until _Now() = GUICtrlRead($date)
    MsgBox(0, "", "matched")
EndFunc
Did the light bulb illuminate? :)

M23

 

 

thank you bro

i'm so idiot 

i hope i'm not reducing this forum level

  • Moderators
Posted

alexander95,

Rather than feeling sorry for yourself, learn from the above and try some basic errorchecking yourself before posting next time. For example, if you have a comparison that is not working, make sure that you are comparing things which are alike - if a file operation does not work, check the path that you are passing to it. etc, etc. :)

It is experience that suggests where to look to find problems - so build up your own experience level, simple really. ;)

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:

  Reveal hidden contents

 

Posted

This is work as expected for your project:

#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <date.au3>


    GUICreate("My GUI get date", 200, 200, 800, 200)
    $date = GUICtrlCreateDate("", 10, 10, 185, 20)
    $button = GUICtrlCreateButton("", 50, 50, 100, 50)

    ; to select a specific default format
    $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW
    $style = "yyyy/MM/d HH:mm:ss"
    GUICtrlSendMsg($date, $DTM_SETFORMAT_, 0, $style)

    GUISetState()

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then Exit
    if $nMsg = $button then but()
WEnd

func but()
    do
        Sleep (1000)
    Until _DateDiff("s", _NowCalc(), GUICtrlRead($date)) <= 0
    MsgBox(0, "", "matched")
EndFunc

 

See Melba's explanation :)

Posted (edited)

I would change these two lines of code.

$style = "M/d/yyyy hh:mm:ss tt"

to

$style = "M/d/yyyy h:mm:ss tt"

and

Until _Now() = GUICtrlRead($date)

to

Until _Now() > GUICtrlRead($date)
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <date.au3>


    GUICreate("My GUI get date", 200, 200, 800, 200)
    $date = GUICtrlCreateDate("", 10, 10, 185, 20)
    $button = GUICtrlCreateButton("START", 50, 50, 100, 50)

    ; to select a specific default format
    $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW
    $style = "M/d/yyyy h:mm:ss tt"
    GUICtrlSendMsg($date, $DTM_SETFORMAT_, 0, $style)

    GUISetState()

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then Exit
    if $nMsg = $button then but()
WEnd

func but()
    GUICtrlSetState($button, $GUI_DISABLE)
    do
    Sleep (1000)
    Until _Now() > GUICtrlRead($date)
    MsgBox(0, "", "matched")
EndFunc

EDIT: Added code

Edited by NewPlaza
Posted
  On 8/27/2013 at 1:23 PM, NewPlaza said:

I would change these two lines of code.

$style = "M/d/yyyy hh:mm:ss tt"

to

$style = "M/d/yyyy h:mm:ss tt"

and

Until _Now() = GUICtrlRead($date)

to

Until _Now() > GUICtrlRead($date)
#include <GUIConstantsEx.au3>
#include <DateTimeConstants.au3>
#include <date.au3>


    GUICreate("My GUI get date", 200, 200, 800, 200)
    $date = GUICtrlCreateDate("", 10, 10, 185, 20)
    $button = GUICtrlCreateButton("START", 50, 50, 100, 50)

    ; to select a specific default format
    $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW
    $style = "M/d/yyyy h:mm:ss tt"
    GUICtrlSendMsg($date, $DTM_SETFORMAT_, 0, $style)

    GUISetState()

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then Exit
    if $nMsg = $button then but()
WEnd

func but()
    GUICtrlSetState($button, $GUI_DISABLE)
    do
    Sleep (1000)
    Until _Now() > GUICtrlRead($date)
    MsgBox(0, "", "matched")
EndFunc

EDIT: Added code

 

what is the difference in = and < in this case ?

  • Moderators
Posted

alexander95,

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 immediately above your post and it just pads the thread unneccessarily. ;)

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:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

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