Sign in to follow this  
Followers 0
HockeyFan

Help disallowing weekends being selection on calendar

5 posts in this topic

Hello,

I would like some assistance on how to exclude certain days from being selected from a GUI Calendar.

I found the following script by Kylomas which does almost exactly what I would like to accomplish...

#include <StaticConstants.au3>
#include <DateTimeConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

#AutoIt3Wrapper_Add_Constants=n

local $gui010   =   guicreate('Date Time Example',300,300)
local $DTctl    =   GUICtrlCreateDate('',20,20,200,20)
local $status   =   guictrlcreatelabel('',20,280,260,20,$SS_SUNKEN)
                    GUICtrlSetColor(-1,0xaa0000)
                    guisetstate()

GUIRegisterMsg($WM_NOTIFY,'WM_NOTIFY')

while 1
    switch guigetmsg()
        case $GUI_EVENT_CLOSE
            Exit
        case $DTctl
            ConsoleWrite('date selected = ' & guictrlread($DTctl)  & @LF)
    EndSwitch
wend

func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMDATETIMECHANGE

    $tNMDATETIMECHANGE  = dllstructcreate($tagNMDATETIMECHANGE, $ilParam)
    $hWndFrom           = HWnd(DllStructGetData($tNMDATETIMECHANGE, "hWndFrom"))
    $iIDFrom            = DllStructGetData($tNMDATETIMECHANGE, "IDFrom")
    $iCode              = DllStructGetData($tNMDATETIMECHANGE, "Code")
    local $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW

    switch $hWndFrom
        case guictrlgethandle($DTctl)
            switch $iCode
                case $DTN_DATETIMECHANGE
                    if dllstructgetdata($tNMDATETIMECHANGE, 'DOW') = 0 then
                        guictrlsetdata($status,'  Invalid Selection - Re-pick Date')
                        GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, '  SUNDAY_INVALID - REPICK')
                    endif
                case $DTN_DROPDOWN
                    guictrlsetdata($status,'')
                    guictrlsendmsg($DTctl, $DTM_SETFORMAT_, 0, "dddd, MMMM dd, yyyy")
            EndSwitch
    EndSwitch

    return $GUI_RUNDEFMSG

endfunc

...but I want to exclude all weekend days (Saturday & Sunday) instead of just Sunday.  I am able to change the "DOW" that is selected by changing the value, but if I add an additional Case statement, the script does not function as I would expect.

What am I missing??

#include <StaticConstants.au3>
#include <DateTimeConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

#AutoIt3Wrapper_Add_Constants=n

local $gui010   =   guicreate('Select Date',300,300)
local $DTctl    =   GUICtrlCreateDate('',20,20,200,20)
local $status   =   guictrlcreatelabel('',20,280,260,20,$SS_SUNKEN)
                    GUICtrlSetColor(-1,0xaa0000)
                    guisetstate()

GUIRegisterMsg($WM_NOTIFY,'WM_NOTIFY')

while 1
    switch guigetmsg()
        case $GUI_EVENT_CLOSE
            Exit
        case $DTctl
            ConsoleWrite('date selected = ' & guictrlread($DTctl)  & @LF)
    EndSwitch
wend

func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMDATETIMECHANGE

    $tNMDATETIMECHANGE  = dllstructcreate($tagNMDATETIMECHANGE, $ilParam)
    $hWndFrom           = HWnd(DllStructGetData($tNMDATETIMECHANGE, "hWndFrom"))
    $iIDFrom            = DllStructGetData($tNMDATETIMECHANGE, "IDFrom")
    $iCode              = DllStructGetData($tNMDATETIMECHANGE, "Code")
    local $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW

    switch $hWndFrom
        case guictrlgethandle($DTctl)
            ;MsgBox(0,"", dllstructgetdata($tNMDATETIMECHANGE, 'DOW'))
            ;MsgBox(0,"", $iCode)
            switch $iCode
                case $DTN_DATETIMECHANGE
                    if dllstructgetdata($tNMDATETIMECHANGE, 'DOW') = 0 then
                        guictrlsetdata($status,'  Invalid Selection - Re-pick Date')
                        GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, '  SUNDAY_INVALID - REPICK')
                    endif
                case $DTN_DATETIMECHANGE
                    if dllstructgetdata($tNMDATETIMECHANGE, 'DOW') = 6 then
                        guictrlsetdata($status,'  Invalid Selection - Re-pick Date')
                        GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, '  SATURDAY_INVALID - REPICK')
                    endif
                case $DTN_DROPDOWN
                    guictrlsetdata($status,'')
                    guictrlsendmsg($DTctl, $DTM_SETFORMAT_, 0, "dddd, MMMM dd, yyyy")
            EndSwitch
    EndSwitch
    return $GUI_RUNDEFMSG

endfunc

Share this post


Link to post
Share on other sites



Try this line

If DllStructGetData($tNMDATETIMECHANGE, 'DOW') = 0 Or  DllStructGetData($tNMDATETIMECHANGE, 'DOW') = 6 Then

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

 

Try this line

If DllStructGetData($tNMDATETIMECHANGE, 'DOW') = 0 Or  DllStructGetData($tNMDATETIMECHANGE, 'DOW') = 6 Then

BrewManNH,

Thank you for that suggestion...that works beautifully for me! 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

....

What am I missing??

#include <StaticConstants.au3>
#include <DateTimeConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

#AutoIt3Wrapper_Add_Constants=n

local $gui010   =   guicreate('Select Date',300,300)
local $DTctl    =   GUICtrlCreateDate('',20,20,200,20)
local $status   =   guictrlcreatelabel('',20,280,260,20,$SS_SUNKEN)
                    GUICtrlSetColor(-1,0xaa0000)
                    guisetstate()

GUIRegisterMsg($WM_NOTIFY,'WM_NOTIFY')

while 1
    switch guigetmsg()
        case $GUI_EVENT_CLOSE
            Exit
        case $DTctl
            ConsoleWrite('date selected = ' & guictrlread($DTctl)  & @LF)
    EndSwitch
wend

func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMDATETIMECHANGE

    $tNMDATETIMECHANGE  = dllstructcreate($tagNMDATETIMECHANGE, $ilParam)
    $hWndFrom           = HWnd(DllStructGetData($tNMDATETIMECHANGE, "hWndFrom"))
    $iIDFrom            = DllStructGetData($tNMDATETIMECHANGE, "IDFrom")
    $iCode              = DllStructGetData($tNMDATETIMECHANGE, "Code")
    local $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW

    switch $hWndFrom
        case guictrlgethandle($DTctl)
            ;MsgBox(0,"", dllstructgetdata($tNMDATETIMECHANGE, 'DOW'))
            ;MsgBox(0,"", $iCode)
            switch $iCode
                case $DTN_DATETIMECHANGE
                    if dllstructgetdata($tNMDATETIMECHANGE, 'DOW') = 0 then
                        guictrlsetdata($status,'  Invalid Selection - Re-pick Date')
                        GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, '  SUNDAY_INVALID - REPICK')
                    endif
                case $DTN_DATETIMECHANGE
                    if dllstructgetdata($tNMDATETIMECHANGE, 'DOW') = 6 then
                        guictrlsetdata($status,'  Invalid Selection - Re-pick Date')
                        GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, '  SATURDAY_INVALID - REPICK')
                    endif
                case $DTN_DROPDOWN
                    guictrlsetdata($status,'')
                    guictrlsendmsg($DTctl, $DTM_SETFORMAT_, 0, "dddd, MMMM dd, yyyy")
            EndSwitch
    EndSwitch
    return $GUI_RUNDEFMSG

endfunc

@HockeyFan

I noticed BrewManNH fix does not differentiate invalid days - Saturday or Sunday.

In your "What am  I missing??" example in 1st post, you have two "$DTN_DATETIMECHANGE" Cases.  The second "$DTN_DATETIMECHANGE" Case will never be accessed.

The easiest fix is to add ContinueCase to the end of the first "$DTN_DATETIMECHANGE" Case:-

#include <StaticConstants.au3>
#include <DateTimeConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

#AutoIt3Wrapper_Add_Constants=n

Local $gui010 = GUICreate('Select Date', 300, 300)
Local $DTctl = GUICtrlCreateDate('', 20, 20, 200, 20)
Local $status = GUICtrlCreateLabel('', 20, 280, 260, 20, $SS_SUNKEN)
GUICtrlSetColor(-1, 0xaa0000)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $DTctl
            ConsoleWrite('date selected = ' & GUICtrlRead($DTctl) & @LF)
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMDATETIMECHANGE

    $tNMDATETIMECHANGE = DllStructCreate($tagNMDATETIMECHANGE, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMDATETIMECHANGE, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMDATETIMECHANGE, "IDFrom")
    $iCode = DllStructGetData($tNMDATETIMECHANGE, "Code")
    Local $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW

    Switch $hWndFrom
        Case GUICtrlGetHandle($DTctl)
            ;MsgBox(0,"", dllstructgetdata($tNMDATETIMECHANGE, 'DOW'))
            ;MsgBox(0,"", $iCode)
            Switch $iCode
                Case $DTN_DATETIMECHANGE
                    If DllStructGetData($tNMDATETIMECHANGE, 'DOW') = 0 Then
                        GUICtrlSetData($status, '  Invalid Selection - Re-pick Date')
                        GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, '  SUNDAY_INVALID - REPICK')
                    EndIf
                    ContinueCase
                Case $DTN_DATETIMECHANGE
                    If DllStructGetData($tNMDATETIMECHANGE, 'DOW') = 6 Then
                        GUICtrlSetData($status, '  Invalid Selection - Re-pick Date')
                        GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, '  SATURDAY_INVALID - REPICK')
                    EndIf
                Case $DTN_DROPDOWN
                    GUICtrlSetData($status, '')
                    GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, "dddd, MMMM dd, yyyy")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY

Alternatively, the two "$DTN_DATETIMECHANGE" Cases can be combined into one "$DTN_DATETIMECHANGE" Case:-

#include <StaticConstants.au3>
#include <DateTimeConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

#AutoIt3Wrapper_Add_Constants=n

Local $gui010 = GUICreate('Select Date', 300, 300)
Local $DTctl = GUICtrlCreateDate('', 20, 20, 200, 20)
Local $status = GUICtrlCreateLabel('', 20, 280, 260, 20, $SS_SUNKEN)
GUICtrlSetColor(-1, 0xaa0000)
GUISetState()

GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $DTctl
            ConsoleWrite('date selected = ' & GUICtrlRead($DTctl) & @LF)
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMDATETIMECHANGE

    $tNMDATETIMECHANGE = DllStructCreate($tagNMDATETIMECHANGE, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMDATETIMECHANGE, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMDATETIMECHANGE, "IDFrom")
    $iCode = DllStructGetData($tNMDATETIMECHANGE, "Code")
    Local $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW

    Switch $hWndFrom
        Case GUICtrlGetHandle($DTctl)
            ;MsgBox(0,"", dllstructgetdata($tNMDATETIMECHANGE, 'DOW'))
            ;MsgBox(0,"", $iCode)
            Switch $iCode                
                Case $DTN_DATETIMECHANGE
                    If DllStructGetData($tNMDATETIMECHANGE, 'DOW') = 0 Then
                        GUICtrlSetData($status, '  Invalid Selection - Re-pick Date')
                        GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, '  SUNDAY_INVALID - REPICK')
                    ElseIf DllStructGetData($tNMDATETIMECHANGE, 'DOW') = 6 Then
                        GUICtrlSetData($status, '  Invalid Selection - Re-pick Date')
                        GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, '  SATURDAY_INVALID - REPICK')
                    EndIf
                    #ce
                Case $DTN_DROPDOWN
                    GUICtrlSetData($status, '')
                    GUICtrlSendMsg($DTctl, $DTM_SETFORMAT_, 0, "dddd, MMMM dd, yyyy")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_NOTIFY
Edited by Malkey

Share this post


Link to post
Share on other sites

If you use ContinueCase, you should probably just use it to abort processing the first selection instead of using it to just drop down into the next Case block. Otherwise it serves no purpose doing it that way, and a single If/Elseif/Endif block would be a much better choice.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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