Jump to content

DTP - Simplify Coding Help Required


Recommended Posts

Hello All,

The Date-Time-Picker has me stumped once again. Two DTP on a form. When DTP1 is changed, I want to automatically change DTP2 to the DTP1's date. Well, it is working but I coded it just to get it to work and it appears as a kludge. Now I need someone with more knowledge to reduce the coding, make it more efficient or show me a differnet way of doing things.

It seems that I have to change the format style of DTP1 to "yyyy-MM-dd", then do a GUICtrlSetData(DTP2,GUICtrlRead(DTP1)), just to get it to work, then change DTP1 style back to "ddd - MM/dd/yy" (for display purposes).

There is a lot of format setting required doing it my way. I'd like to do something like GUICtrlSetData(DTP2,GUICtrlRead(DTP1),"yyyy-MM-dd") if possible.

CODE
#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

#include <GuiDateTimePicker.au3>

#Include <Date.au3>

Local $GUI, $Btn_COLORREF, $Btn_BGR, $Btn_RGB, $iMemo

Dim $DTN_FIRST = -760

Dim $DateStyle = "ddd - MM/dd/yy"

Dim $NameStyle = "yyMMdd"

Dim $SetDateData = "yyyy-MM-dd"

Dim $DispDate = ""

Dim $wrkDate = ""

Global Const $DTM_SETFORMAT_ = 0x1032

Global $fFlag = False, $aTime[8]

#Region ### START Koda GUI section ### Form=C:\ReportSetupApp\frm098002.kxf

$frm098002 = GUICreate("Test of Date Params", 646, 209, 195, 124)

$btnExit = GUICtrlCreateButton("Exit", 528, 144, 65, 33)

$Group2 = GUICtrlCreateGroup("Date Parameters", 24, 32, 593, 89)

$Date1F = GUICtrlCreateDate("2009/05/14 10:04:35", 113, 74, 161, 25)

$Date1T = GUICtrlCreateDate("2009/05/14 10:04:35", 281, 74, 161, 25)

$Date1Name = GUICtrlCreateInput("DispDate", 457, 74, 137, 21)

;$DateWork = GUICtrlCreateDate("2009/11/22 10:04:35", 113, 110, 161, 25)

$Label13 = GUICtrlCreateLabel("---- From Date ----", 140, 55, 83, 17)

$Label14 = GUICtrlCreateLabel("---- Thru Date ----", 311, 55, 82, 17)

$Label15 = GUICtrlCreateLabel("---- File Date ----", 477, 55, 78, 17)

GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

;Set Initial Styles and Formats for GUI Form

GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $DateStyle)

GUICtrlSendMsg($Date1T, $DTM_SETFORMAT_, 0, $DateStyle)

GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $NameStyle)

GUICtrlSetData($Date1Name, GUICtrlRead($Date1F))

GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $DateStyle)

GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY")

$Date1_State = GUICtrlRead($Date1F)

Opt('MustDeclareVars', 1)

dim $nMsg = ""

While 1

$nMsg = GUIGetMsg()

Select

Case $nMsg = $btnExit

Exit

EndSelect

If GUICtrlRead($Date1F) <> $Date1_State Then

GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $NameStyle)

GUICtrlSetData($Date1Name, GUICtrlRead($Date1F))

GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $SetDateData)

GUICtrlSetData($Date1T,GUICtrlRead($Date1F))

GUICtrlSendMsg($Date1T, $DTM_SETFORMAT_, 0, $DateStyle)

GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $DateStyle)

$Date1_State = GUICtrlRead($Date1F)

Endif

WEnd

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

Opt('MustDeclareVars', 0)

#forceref $hWnd, $iMsg, $iwParam

Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tBuffer, $tBuffer2

$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)

$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))

$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")

$iCode = DllStructGetData($tNMHDR, "Code")

Switch $hWndFrom

Case $iCode

Switch $iCode

Case $DTN_DATETIMECHANGE; Sent by a date and time picker (DTP) control whenever a change occurs

$tInfo = DllStructCreate($tagNMDATETIMECHANGE, $ilParam)

$aTime = _Date_Time_SystemTimeToArray($tInfo)

$fFlag = True

Return 0

EndSwitch

EndSwitch

Return $GUI_RUNDEFMSG

EndFunc ;==>MY_WM_NOTIFY

I was thinking about a hidden DTP that I could change the formats without affecting the window contents ....but.... there must be a better way.

Show me the way,

Freedom1

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiDateTimePicker.au3>
#include <Date.au3>

Local $GUI, $Btn_COLORREF, $Btn_BGR, $Btn_RGB, $iMemo
Dim $DTN_FIRST = -760
Dim $DateStyle = "ddd - MM/dd/yy"
Dim $NameStyle = "yyMMdd"
Dim $SetDateData = "yyyy-MM-dd"
Dim $DispDate = ""
Dim $wrkDate = ""

Global Const $DTM_SETFORMAT_ = 0x1032
Global $fFlag = False, $aTime[8]


#Region ### START Koda GUI section ### Form=C:\ReportSetupApp\frm098002.kxf
$frm098002 = GUICreate("Test of Date Params", 646, 209, 195, 124)
$btnExit = GUICtrlCreateButton("Exit", 528, 144, 65, 33)
$Group2 = GUICtrlCreateGroup("Date Parameters", 24, 32, 593, 89)
$Date1F = GUICtrlCreateDate("2009/05/14 10:04:35", 113, 74, 161, 25)
$hDate1F = GUICtrlGetHandle(-1)
$Date1T = GUICtrlCreateDate("2009/05/14 10:04:35", 281, 74, 161, 25)
$hDate1T = GUICtrlGetHandle(-1)
$Date1Name = GUICtrlCreateInput("DispDate", 457, 74, 137, 21)
;$DateWork = GUICtrlCreateDate("2009/11/22 10:04:35", 113, 110, 161, 25)
$Label13 = GUICtrlCreateLabel("---- From Date ----", 140, 55, 83, 17)
$Label14 = GUICtrlCreateLabel("---- Thru Date ----", 311, 55, 82, 17)
$Label15 = GUICtrlCreateLabel("---- File Date ----", 477, 55, 78, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;Set Initial Styles and Formats for GUI Form
GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $DateStyle)
GUICtrlSendMsg($Date1T, $DTM_SETFORMAT_, 0, $DateStyle)
GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $NameStyle)
GUICtrlSetData($Date1Name, GUICtrlRead($Date1F))
GUICtrlSendMsg($Date1F, $DTM_SETFORMAT_, 0, $DateStyle)

GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY")
$Date1_State = GUICtrlRead($Date1F)

Opt('MustDeclareVars', 1)

Dim $nMsg = ""
While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $btnExit
            Exit
    EndSelect
WEnd

Func MY_WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMDTC = DllStructCreate($tagNMDATETIMECHANGE, $ilParam)
    Local $avData[7], $avMembers = StringSplit('Year|Month|Day|Hour|Minute|Second', '|')
    
    If DllStructGetData($tNMDTC, 'hWndFrom') = $hDate1F Then
        If DllStructGetData($tNMDTC, 'Code') = $DTN_DATETIMECHANGE Then
            
            Switch DllStructGetData($tNMDTC, 'Flag')
                ;Case $GDT_NONE
                    ;
                Case $GDT_VALID
                    For $i = 1 To $avMembers[0]
                        $avData[$i] = DllStructGetData($tNMDTC, $avMembers[$i])
                    Next
                    _GUICtrlDTP_SetSystemTime($hDate1T, $avData)
            EndSwitch
        EndIf
    EndIf
        
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_NOTIFY

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