Jump to content

Date Control


LurchMan
 Share

Go to solution Solved by Melba23,

Recommended Posts

Hello Everyone - 

I'm trying to create a date control that is empty as the default value.  I can't figure out how to accomplish this.  I have tried setting the data to "" and I've tried using the $DTS_SHOWNONE and then setting the state to $GUI_UNCHECKED but to no avail.  The end result I would like is to let the user select Date and time within the same control, however they could leave it blank.  I'm building a searching application with multiple ways to search to items (date / time being one) but they do not have to use all search terms. 

Here's my sample script to show how I have it setup currently:

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

Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("Form1", 250, 200, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$hDate = GUICtrlCreateDate ("", 10, 10, -1, -1, $DTS_SHOWNONE)
GUICtrlSetData (-1, "")
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func Form1Close()
    Exit
EndFunc

Thank you in advance for any help.

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

  • Moderators
  • Solution

LurchMan,

How about this - the picker is blank until you select a date in the dropdown: :huh:

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

Opt("GUIOnEventMode", 1)

$hGUI = GUICreate("Form1", 250, 200)

GUISetOnEvent($GUI_EVENT_CLOSE, "_Close")

$cDate = GUICtrlCreateDate ("", 10, 10)
GUICtrlSendMsg($cDate, $DTM_SETFORMATW, 0, " ") ; Format as a blank

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Sleep(10)
WEnd

Func _Close()
    Exit
EndFunc


Func _WM_NOTIFY($hWnd, $iMsg, $wPram, $lParam)

    $tStruct = DllStructCreate($tagNMHDR, $lParam)

    $cID = DllStructGetData($tStruct, "IDFrom")
    $iCode = DllStructGetData($tStruct, "Code")

    ; Wait until the date picker is opened and closed
    If $cID = $cDate And $iCode = $DTN_CLOSEUP Then
        GUICtrlSendMsg($cDate, $DTM_SETFORMATW, 0, "hh:mm:ss dd/MM/yyyy") ; Format as time and date
    EndIf

EndFunc
I set the format to include time as well as date as you wanted. ;)

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

As usual Melba - Thank you for the spot on answer.  This solves the problem. 

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

  • Moderators

LurchMan,

Glad I could help. :)

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

  • 1 year later...

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