Sign in to follow this  
Followers 0
MePHiTiC

Date problem with GUICtrlCreateMonthCal

9 posts in this topic

I'm using the following to grab a date from the GUI calendar:

$date = GUICtrlCreateMonthCal ( today(), 30, 132, 240, 190)

The $date is coming out as yyyy/mm/dd. I have two questions about this ...

1) how do I get the 4-digit year into a 2-digit format?

2) how can I get the 2-digit year as a variable, the month as a variable, and the day as a variable as I'll be using each part separately?

Thanks for the help!

MePH

Share this post


Link to post
Share on other sites



I'm using the following to grab a date from the GUI calendar:

$date = GUICtrlCreateMonthCal ( today(), 30, 132, 240, 190)

The $date is coming out as yyyy/mm/dd. I have two questions about this ...

1) how do I get the 4-digit year into a 2-digit format?

2) how can I get the 2-digit year as a variable, the month as a variable, and the day as a variable as I'll be using each part separately?

Thanks for the help!

MePH

2nd first. StringSplit, separator is "/". Now for the first question: StringRight() on the array element that represents the year.

Cheers

Kut


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

2nd first. StringSplit, separator is "/". Now for the first question: StringRight() on the array element that represents the year.

Cheers

Kut

AWESOME Kut ... Both worked perfectly ... Thanks for the help!

MePH

Share this post


Link to post
Share on other sites

AWESOME Kut ... Both worked perfectly ... Thanks for the help!

MePH

I know this is a bit old, but I thought I'd add to it instead of making a new thread :)

I still don't get it. I read the helpfile, and I just don't see how to turn this into a string the split the string.

here is what I have:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <DateTimeConstants.au3>
Global $Calendar, $date, $day, $month, $year, $string, $split

$Calendar = GUICtrlCreateMonthCal("@YEAR/@MON/@MDAY", 308, 16, 191, 148, BitOR($MCS_NOTODAY,$WS_BORDER), 0)
$date = GUICtrlRead($Calendar)
$String = String($date)
$Split = StringSplit($string, '/')
$day = StringRight($split, 2)
$month = StringMid($split, 6, 2)
$year = StringLeft($split, 4)

MSGBox(0, "Date", $month)

I'm not looking for an answer by any means, more so a "hey! idiot! did you try reading _____? or what the hell were you thinking when you wrote ____?"

:P just keepin the spirits up.


children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :)

Share this post


Link to post
Share on other sites

StringSplit - if successful - returns an array.

You have to use array elements in your StringRight, StringMid ... statements ($split[1], $split[2] ...) and not $split (the array ID) as you have used.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

StringSplit - if successful - returns an array.

You have to use array elements in your StringRight, StringMid ... statements ($split[1], $split[2] ...) and not $split (the array ID) as you have used.

So I'm guessing I didn't do stringsplit right? Or what's my problem here, because even the arrays didn't work.


children may smile; the wise ponder- Dr. Holmes of Hardvard Medical School on an Ether BingeLove Makes The World Go Round?So does five shots of tequila. What's your point?[quote name='Valik' date='Jun 5 2008, 05:13 PM']wraithdu, 24 hours. Said I have a bad attitude, just driving the point home with a ban.[/quote]This is classic. :)

Share this post


Link to post
Share on other sites

The problem(s): you're doing a StringLeft ... after StringSplit (after the string was splitted in components) ... and ... your code is kinda messed up ...

Here is how it should work:

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 226, 204, 193, 125)
$MonthCal1 = GUICtrlCreateMonthCal("2008/06/30", 16, 16, 193, 169)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MonthCal1
            $String = GUICtrlRead($MonthCal1)
            $Split = StringSplit($string, '/')
            $day = $split[3]
            $month = $split[2]
            $year = $split[1]
            MSGBox(0, "Date", $month)
    EndSwitch
WEnd

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

enaiman, your calendar control or wrapper, or whatever it might be called, is fabulous! I've been looking for something like this for years! Thanks.

I've run into 2 snags that I can't seem to get myself out of.

1. I can't figure out how to make my additional date entry work, the one that adds a day of the week. I've added the custom variable code to get the week day in the format needed, I just don't know how to, what would one call it, activate it, or whatever.

2. This one is stupid, I'm sure. A close button I added doesn't work and I don't have enough GUI experience yet to figure out why.

Here's my variation of the above:

;#include <DateTimeConstants.au3>
;#include <GUIConstantsEx.au3>    ; not needed since I extracted $GUI_EVENT_CLOSE syntax, etc., below from the appropriate UDF
;#include <WindowsConstants.au3>    ; not needed since I extracted $WS_EX_TOPMOST syntax, etc., below from the appropriate UDF
#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon("Shell32.dll", 276)     ; changes the icon displayed in the systray


;----- Today's date code: -------------------------------------------------------------------------
#include<Date.au3>
$Today = _Now()
$ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(@WDAY,1) ), 2)
;--------------------------------------------------------------------------------------------------


;=========================================================================
Global Const $GUI_EVENT_CLOSE = -3     ; by using this constant, could leave out reference to "#include <GUIConstants.au3>", which in turn referenced this variable, with this exact value, from "GUIConstantsEx.au3"
Global Const $WS_EX_TOPMOST    = 0x00000008     ;   put this in so that no need to have UDF present when compiling
$Form1 = GUICreate("Date Picker", 225, 230, 750, 125, -1, $WS_EX_TOPMOST)     ; width, height, left, top, "-1, $WS_EX_TOPMOST" makes GUI topmost
$MonthCal1 = GUICtrlCreateMonthCal($Today, 16, 16, 193, 169)     ; left, top, width, height
GUISetIcon("Shell32.dll", 276)     ; this changes icon in upper left-hand corner to your chosen one
;----------------------------------------------------------
$Info = GUICtrlCreateLabel("?", 25, 200, 15, 15)     ; left, top, width, height
GUICtrlSetTip(-1, "Find and choose any date and click on it." & @CRLF & "It will then be sent to the clipboard.")     ; label tooltip
;----------------------------------------------------------
$Close = GUICtrlCreateButton("Close", 160, 195, 50, 25, 0)     ; left, top, width, height
GUICtrlSetOnEvent(-1, "Close")
GUICtrlSetTip(-1, "Close and exit.")     ; button tooltip     ; button tooltip
; ----------------------
GUISetState(@SW_SHOW)
;=========================================================================

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MonthCal1
            $String = GUICtrlRead($MonthCal1)
            $Split = StringSplit($string, '/')
            $day = $split[3]
            $month = $split[2]
            $year = $split[1]
            ;MSGBox(0, "Date", $month)
            ClipPut($year & "." & $month & "." & $day & "." & $ShortDayMyFormat)
            Sleep(100)
            Beep(1000,50)
    EndSwitch
WEnd


Func Close()
    Exit     ; finished
EndFunc  ;==>close

(Pls, pls ignore the idiosyncratic way I have with the UDFs, thanks!)

Cheers. ;)

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@Diana (Cda)

The exit problem is solved by removing the OnEventMode function call - you have combined the 2 styles in your script and it didn't work (I've removed that function call and added the correct entry).

Your first issue: I'm afraid I don't understand what do you mean???

#NoTrayIcon     ; AutoIt's icon doesn't show in systray
TraySetIcon("Shell32.dll", 276)     ; changes the icon displayed in the systray


;----- Today's date code: -------------------------------------------------------------------------
#include<Date.au3>
$Today = _Now()
$ShortDayMyFormat = StringMid("Sn,Mn,Tu,Wd,Th,Fr,Sa", StringInStr("SunMonTueWedThuFriSat", _DateDayOfWeek(@WDAY,1) ), 2)
;--------------------------------------------------------------------------------------------------


;=========================================================================
Global Const $GUI_EVENT_CLOSE = -3     ; by using this constant, could leave out reference to "#include <GUIConstants.au3>", which in turn referenced this variable, with this exact value, from "GUIConstantsEx.au3"
Global Const $WS_EX_TOPMOST    = 0x00000008     ;   put this in so that no need to have UDF present when compiling
$Form1 = GUICreate("Date Picker", 225, 230, 750, 125, -1, $WS_EX_TOPMOST)     ; width, height, left, top, "-1, $WS_EX_TOPMOST" makes GUI topmost
$MonthCal1 = GUICtrlCreateMonthCal($Today, 16, 16, 193, 169)     ; left, top, width, height
GUISetIcon("Shell32.dll", 276)     ; this changes icon in upper left-hand corner to your chosen one
;----------------------------------------------------------
$Info = GUICtrlCreateLabel("?", 25, 200, 15, 15)     ; left, top, width, height
GUICtrlSetTip(-1, "Find and choose any date and click on it." & @CRLF & "It will then be sent to the clipboard.")     ; label tooltip
;----------------------------------------------------------
$Close = GUICtrlCreateButton("Close", 160, 195, 50, 25, 0)     ; left, top, width, height
;GUICtrlSetOnEvent(-1, "Close") - THIS is used only for OnEventMode - in this form of script it doesn't work
GUICtrlSetTip(-1, "Close and exit.")     ; button tooltip     ; button tooltip
; ----------------------
GUISetState(@SW_SHOW)
;=========================================================================

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $MonthCal1
            $String = GUICtrlRead($MonthCal1)
            $Split = StringSplit($string, '/')
            $day = $split[3]
            $month = $split[2]
            $year = $split[1]
            ;MSGBox(0, "Date", $month)
            ClipPut($year & "." & $month & "." & $day & "." & $ShortDayMyFormat)
            Sleep(100)
            Beep(1000,50)
        Case $Close             ;replaces the Close function call (wrongly used in OnEventMode)
            Exit
    EndSwitch
WEnd
Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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