AutoHotkey Community

It is currently May 27th, 2012, 10:50 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: April 9th, 2008, 12:15 pm 
Offline

Joined: April 8th, 2008, 7:39 pm
Posts: 8
Code:
; =========================================================
; Templates für Current Date in ISO-FORMAT: YYYY-MM-DD
; =========================================================
;Key: F9  --> "2006-01-17"

F9::
FormatTime, TimeString, , yyyy-MM-dd
;MsgBox %TimeString%
send %TimeString%
return

; =========================================================
; Templates für Current Date in ISO-FORMAT: YYYY-MM-DD" "
; =========================================================
;Key: Alt+F9  --> "2006-01-17 "

!F9::
FormatTime, TimeString, , yyyy-MM-dd
;MsgBox %TimeString%
send %TimeString%{Space}
return

; =========================================================
; Templates für Current Date in ISO-FORMAT: DD.MM.YYYY
; =========================================================
;Key: CTRL+F9  --> "17.01.2006"

^F9::
FormatTime, TimeString, , dd.MM.yyyy
;MsgBox %TimeString%
send %TimeString%
return


; =========================================================
; Templates für Current Date in ISO-FORMAT: DD.MM.YYYY" "
; =========================================================
;Key: CTRL+Alt+F9  --> "17.01.2006 "

^!F9::
FormatTime, TimeString, , dd.MM.yyyy
;MsgBox %TimeString%
send %TimeString%{Space}
return



; =========================================================
; Templates for Calender Function in different date formats
;   
;   DD. MMMM YYYY   -   17. Januar 2006   -   DIN 5008 (German alphanumeric)
;   DD. MMM. YYYY   -   17. Jan. 2006   - DIN 5008 (German alphanumeric short)
;   YYYY-MM-DD      -   2006-01-17   -   ISO 8601 (standard/extended Format)
;   YYYYMMDD        -   20060117   -   ISO 8601 (Basisformat)
;   YY-MM-DD        -   06-01-17   -   ISO 8601/2000 (Shortformat old)
;   YYMMDD          -   060117   -   ISO 8601/2000 (Shortformat IT)
;   DD.MM.YYYY      -   17.01.2006   -   DIN 5008 (German optional writing)
;   DD.MM.YY        -   17.01.06   -   DIN 5008 (German optional writing short)
;   DD/MM/YYYY      -   17/01/2006
;   DD/MM/YY        -   17/01/06
;   DDMMYYYY        -   17012006
;   DDMMYY          -   170106
;   
; =========================================================
;Key: Shift+CTRL+F9 -> GUI Selection for Date in a spec. Format

^+F9::
   SendInput % CalendarDate()
return 

CalendarDate()
{
   Global F_Date
   Global FormatChoice
   Gui, 3:Add, Text, x6 y10 w130 h20,Enter the date :
   Gui, 3:Add, DateTime, x6 y25 w130 h20 vF_Date,
   Gui, 3:Add, Text, x6 y50 w130 h20,Choose your format :
   Gui, 3:Add, DropDownList, x6 y65 w130 h180 vFormatChoice, YYYY-MM-DD|DD.MM.YYYY||DD. MMMM YYYY|DD. MMM. YYYY|YYYYMMDD|YY-MM-DD|YYMMDD|DD.MM.YY|DD/MM/YYYY|DD/MM/YY|ddmmyyyy|ddmmyy|DAYNAME
   Gui, 3:Add, Button, x6 y95 w60 h20 Default,&OK
   Gui, 3:Add, Button, x76 y95 w60 h20,&Cancel
   Gui, 3:Show, x562 y225 h125 w146, Date
   WinWaitClose, Date, Enter the date
   Return TD_RDate

   3GuiEscape:
      Gui, 3:cancel
      Gui, 3:Destroy
      TD_RDate = 0
   return

   3ButtonCancel:
   3GuiClose:
      Gui, 3:cancel
      Gui, 3:Destroy
   return

   3ButtonOK:
      Gui, 3:submit
      Gui, 3:Destroy
      If FormatChoice = DD. MMMM YYYY
         FormatTime, TD_RDate, %F_Date%, dd. MMMM yyyy
      Else If FormatChoice = DD. MMM. YYYY
         FormatTime, TD_RDate, %F_Date%, dd. MMM. yyyy
      Else If FormatChoice = YYYY-MM-DD
         FormatTime, TD_RDate, %F_Date%, yyyy-MM-dd
      Else If FormatChoice = YYYYMMDD
         FormatTime, TD_RDate, %F_Date%, yyyyMMdd
      Else If FormatChoice = YY-MM-DD
         FormatTime, TD_RDate, %F_Date%, yy-MM-dd
      Else If FormatChoice = YYMMDD
         FormatTime, TD_RDate, %F_Date%, yyMMdd
      Else If FormatChoice = DD.MM.YYYY
         FormatTime, TD_RDate, %F_Date%, dd.MM.yyyy
      Else If FormatChoice = DD.MM.YY
         FormatTime, TD_RDate, %F_Date%, dd.MM.yy
      Else If FormatChoice = DD/MM/YYYY
         FormatTime, TD_RDate, %F_Date%, dd/MM/yyyy
      Else If FormatChoice = DD/MM/YY
         FormatTime, TD_RDate, %F_Date%, dd/MM/yy
      Else If FormatChoice = ddmmyyyy
         FormatTime, TD_RDate, %F_Date%, ddMMyyyy
      Else If FormatChoice = ddmmyy
         FormatTime, TD_RDate, %F_Date%, ddMMyy
      Else If FormatChoice = DAYNAME
         FormatTime, TD_RDate, %F_Date%, dddd
   return
}


F9 (DATE ISO) - "2006-01-17"
+ALT (DATE ISO+Space) - "2006-01-17 "
+CTRL (DATE German) - "17.01.2006"
+CTRL+ALT (DATE German+Space) - "17.01.2006 "
+CTRL+SHIFT (GUI-Selection DATE)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 9th, 2008, 3:49 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
Out of curiousity, why call the GUI in a separate function? Why not directly in that hotkey call? Does that offer an added benefit of some kind? If always found it a bit awkward in my mind to have subroutines inside of functions like that. I'm not ripping on how you did it or anything, just trying to get a better handle on AHK. I'm always learning new things based on how other people do it. :) Thanks!

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 9th, 2008, 7:24 pm 
Offline

Joined: April 8th, 2008, 7:39 pm
Posts: 8
silveredge78 wrote:
Out of curiousity, why call the GUI in a separate function? Why not directly in that hotkey call? Does that offer an added benefit of some kind? If always found it a bit awkward in my mind to have subroutines inside of functions like that. I'm not ripping on how you did it or anything, just trying to get a better handle on AHK. I'm always learning new things based on how other people do it. :) Thanks!


Sorry, did'n get what you mean!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 9th, 2008, 10:20 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
markus2005 wrote:
Code:
^+F9::
   SendInput % CalendarDate()
return 

CalendarDate()
{
   Global F_Date
   Global FormatChoice
   Gui, 3:Add, Text, x6 y10 w130 h20,Enter the date :
   Gui, 3:Add, DateTime, x6 y25 w130 h20 vF_Date,
   Gui, 3:Add, Text, x6 y50 w130 h20,Choose your format :
   Gui, 3:Add, DropDownList, x6 y65 w130 h180 vFormatChoice, YYYY-MM-DD|DD.MM.YYYY||DD. MMMM YYYY|DD. MMM. YYYY|YYYYMMDD|YY-MM-DD|YYMMDD|DD.MM.YY|DD/MM/YYYY|DD/MM/YY|ddmmyyyy|ddmmyy|DAYNAME
   Gui, 3:Add, Button, x6 y95 w60 h20 Default,&OK
   Gui, 3:Add, Button, x76 y95 w60 h20,&Cancel
   Gui, 3:Show, x562 y225 h125 w146, Date
   WinWaitClose, Date, Enter the date
   Return TD_RDate

   3GuiEscape:
      Gui, 3:cancel
      Gui, 3:Destroy
      TD_RDate = 0
   return

   3ButtonCancel:
   3GuiClose:
      Gui, 3:cancel
      Gui, 3:Destroy
   return

   3ButtonOK:
      Gui, 3:submit
      Gui, 3:Destroy
      If FormatChoice = DD. MMMM YYYY
         FormatTime, TD_RDate, %F_Date%, dd. MMMM yyyy
      Else If FormatChoice = DD. MMM. YYYY
         FormatTime, TD_RDate, %F_Date%, dd. MMM. yyyy
      Else If FormatChoice = YYYY-MM-DD
         FormatTime, TD_RDate, %F_Date%, yyyy-MM-dd
      Else If FormatChoice = YYYYMMDD
         FormatTime, TD_RDate, %F_Date%, yyyyMMdd
      Else If FormatChoice = YY-MM-DD
         FormatTime, TD_RDate, %F_Date%, yy-MM-dd
      Else If FormatChoice = YYMMDD
         FormatTime, TD_RDate, %F_Date%, yyMMdd
      Else If FormatChoice = DD.MM.YYYY
         FormatTime, TD_RDate, %F_Date%, dd.MM.yyyy
      Else If FormatChoice = DD.MM.YY
         FormatTime, TD_RDate, %F_Date%, dd.MM.yy
      Else If FormatChoice = DD/MM/YYYY
         FormatTime, TD_RDate, %F_Date%, dd/MM/yyyy
      Else If FormatChoice = DD/MM/YY
         FormatTime, TD_RDate, %F_Date%, dd/MM/yy
      Else If FormatChoice = ddmmyyyy
         FormatTime, TD_RDate, %F_Date%, ddMMyyyy
      Else If FormatChoice = ddmmyy
         FormatTime, TD_RDate, %F_Date%, ddMMyy
      Else If FormatChoice = DAYNAME
         FormatTime, TD_RDate, %F_Date%, dddd
   return
}

Your hotkey calls CalendarDate() which is a function. In that function you generate the GUI. Why not just do something like:

Code:
^+F9::
  Gui, 3:Add, Text, x6 y10 w130 h20,Enter the date :
  Gui, 3:Add, DateTime, x6 y25 w130 h20 vF_Date,
  Gui, 3:Add, Text, x6 y50 w130 h20,Choose your format :
  Gui, 3:Add, DropDownList, x6 y65 w130 h180 vFormatChoice, YYYY-MM-DD|DD.MM.YYYY||DD. MMMM YYYY|DD. MMM. YYYY|YYYYMMDD|YY-MM-DD|YYMMDD|DD.MM.YY|DD/MM/YYYY|DD/MM/YY|ddmmyyyy|ddmmyy|DAYNAME
  Gui, 3:Add, Button, x6 y95 w60 h20 Default,&OK
  Gui, 3:Add, Button, x76 y95 w60 h20,&Cancel
  Gui, 3:Show, x562 y225 h125 w146, Date
  WinWaitClose, Date, Enter the date
  Return TD_RDate

  3GuiEscape:
    Gui, 3:cancel
    Gui, 3:Destroy
    TD_RDate = 0
  Return

  3ButtonCancel:
  3GuiClose:
    Gui, 3:cancel
    Gui, 3:Destroy
  Return

  3ButtonOK:
    Gui, 3:submit
    Gui, 3:Destroy
    If FormatChoice = DD. MMMM YYYY
      FormatTime, TD_RDate, %F_Date%, dd. MMMM yyyy
    Else If FormatChoice = DD. MMM. YYYY
      FormatTime, TD_RDate, %F_Date%, dd. MMM. yyyy
    Else If FormatChoice = YYYY-MM-DD
      FormatTime, TD_RDate, %F_Date%, yyyy-MM-dd
    Else If FormatChoice = YYYYMMDD
      FormatTime, TD_RDate, %F_Date%, yyyyMMdd
    Else If FormatChoice = YY-MM-DD
      FormatTime, TD_RDate, %F_Date%, yy-MM-dd
    Else If FormatChoice = YYMMDD
      FormatTime, TD_RDate, %F_Date%, yyMMdd
    Else If FormatChoice = DD.MM.YYYY
      FormatTime, TD_RDate, %F_Date%, dd.MM.yyyy
    Else If FormatChoice = DD.MM.YY
      FormatTime, TD_RDate, %F_Date%, dd.MM.yy
    Else If FormatChoice = DD/MM/YYYY
      FormatTime, TD_RDate, %F_Date%, dd/MM/yyyy
    Else If FormatChoice = DD/MM/YY
      FormatTime, TD_RDate, %F_Date%, dd/MM/yy
    Else If FormatChoice = ddmmyyyy
      FormatTime, TD_RDate, %F_Date%, ddMMyyyy
    Else If FormatChoice = ddmmyy
      FormatTime, TD_RDate, %F_Date%, ddMMyy
    Else If FormatChoice = DAYNAME
      FormatTime, TD_RDate, %F_Date%, dddd
  Return 

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 10th, 2008, 6:12 pm 
Offline

Joined: April 8th, 2008, 7:39 pm
Posts: 8
OK, now I understand your point.

The result looks the same, but I learnt something like that at the university. The advantage is, to reuse a code in another call

just a simple example:

F9 gives you: "2008-04-10"
and F10 should give "2008-04-10 This is a DATE"

F9 call just the calender function
F10 call the function and adds a String at the end.

If you do that in the Key-Code, you have the code twice. When you do it on a function way, you can reuse the same code in different ways, but you have to implement it just once (no maintaining on/in different places of code).

So, when you want to use a different key for the same function could also be a reason!

I'm not an IT-Prof. But ask one of them and they will explain you many reasons why....


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 10th, 2008, 6:31 pm 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
markus2005> I completely understand what you are talking about. Anytime I can make something a subroutine or a function, I take the time to do it. You never know when a future script might need something like that. I was confused cause that was the only call to that. If I only use something once that is specific to the script, then I just do it normal. If I had seen a second call to it, my question wouldn't have been asked.

So valid point, it just wasn't obvious to me without the second call in what you pasted. :) Thanks for your patience!

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Optimization
PostPosted: August 18th, 2008, 5:43 am 
Offline

Joined: June 12th, 2008, 10:29 am
Posts: 52
Couldn't this section
Code:
    If FormatChoice = DD. MMMM YYYY
      FormatTime, TD_RDate, %F_Date%, dd. MMMM yyyy
    Else If FormatChoice = DD. MMM. YYYY
      FormatTime, TD_RDate, %F_Date%, dd. MMM. yyyy
    Else If FormatChoice = YYYY-MM-DD
      FormatTime, TD_RDate, %F_Date%, yyyy-MM-dd
    Else If FormatChoice = YYYYMMDD
      FormatTime, TD_RDate, %F_Date%, yyyyMMdd
    Else If FormatChoice = YY-MM-DD
      FormatTime, TD_RDate, %F_Date%, yy-MM-dd
    Else If FormatChoice = YYMMDD
      FormatTime, TD_RDate, %F_Date%, yyMMdd
    Else If FormatChoice = DD.MM.YYYY
      FormatTime, TD_RDate, %F_Date%, dd.MM.yyyy
    Else If FormatChoice = DD.MM.YY
      FormatTime, TD_RDate, %F_Date%, dd.MM.yy
    Else If FormatChoice = DD/MM/YYYY
      FormatTime, TD_RDate, %F_Date%, dd/MM/yyyy
    Else If FormatChoice = DD/MM/YY
      FormatTime, TD_RDate, %F_Date%, dd/MM/yy
    Else If FormatChoice = ddmmyyyy
      FormatTime, TD_RDate, %F_Date%, ddMMyyyy
    Else If FormatChoice = ddmmyy
      FormatTime, TD_RDate, %F_Date%, ddMMyy
    Else If FormatChoice = DAYNAME
      FormatTime, TD_RDate, %F_Date%, dddd

be written as

Code:
FormatTime, TD_RDate, %F_Date%, %FormatChoice%
?

All you'd have to do is replace the parameters in the listbox to match actual formats (i.e. proper cases)

From
Code:
Gui, 3:Add, DropDownList, x6 y65 w130 h180 vFormatChoice, YYYY-MM-DD|DD.MM.YYYY||DD. MMMM YYYY|DD. MMM. YYYY|YYYYMMDD|YY-MM-DD|YYMMDD|DD.MM.YY|DD/MM/YYYY|DD/MM/YY|ddmmyyyy|ddmmyy|DAYNAME


To
Code:
Gui, 3:Add, DropDownList, x6 y65 w130 h180 vFormatChoice, yyyy-MM-dd|dd.MM.yyyy||dd. MMMM yyyy|dd. MMM. yyyy|yyyyMMdd|yy-MM-dd|yyMMdd|dd.MM.yy|dd/MM/yyyy|dd/MM/yy|ddMMyyyy|ddMMyy|dddd


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 18th, 2008, 5:51 am 
Offline

Joined: July 25th, 2006, 7:37 pm
Posts: 490
Location: Midwest, USA
vixay> That appears to work from what I can tell. Hooray for streamlining code. :)

_________________
SilverEdge78


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Very nice!
PostPosted: August 18th, 2008, 8:21 pm 
Offline

Joined: April 8th, 2008, 7:39 pm
Posts: 8
Works fine!!!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Yearly Calendar
PostPosted: August 25th, 2008, 11:40 am 
Offline

Joined: June 12th, 2008, 10:29 am
Posts: 52
I wanted to get a yearly calendar... with this functionality... Trying to replace the ATNotes Calendar option with this one.

Any Ideas?

Here is what i have so far... Shows only 3 months, and selects only date from the middle one....

Like people said, double-clicking doesn't work...

Code:
#q:: ;; Show current calendar
  tm = %A_Now%
  tm += -31, Days
  Gui, 4:Add, MonthCal, vSelectedDate0 gGoDate, %tm%
  tm += 31, Days
  Gui, 4:Add, MonthCal, x+10 vSelectedDate1 gGoDate
  ;tm := SubStr(tm, 1, 6)
  tm += 31, Days
  ;tm := SubStr(tm, 1, 6)
  ;tm -= 30, Days
  Gui, 4:Add, MonthCal, x+10 vSelectedDate2 gGoDate, %tm%
  Gui, 4:Add, Button, w60 h20 Default,&OK
  Gui, 4:Add, Button, x+20 w60 h20,&Cancel
  Gui, 4:Show
Return

GoDate:
  MouseGetPos, X1, Y1
  KeyWait, LButton, D T0.1 ; wait for a "double click".
  if errorlevel
     return
  MouseGetPos, X2, Y2
  if (X1 != X2 || Y1 != Y2) ; if the mouse moved...return.
     return
  ;gui, 4:submit, nohide
  ;gui, 4:destroy
  ;msgbox You selected %SelectedDate%%SelectedDate1%%SelectedDate2%!
return

4GuiEscape:
4ButtonCancel:
4GuiClose:
  Gui, 4:cancel
  Gui, 4:Destroy
return

4ButtonOK:
  Gui, 4:submit
  Gui, 4:Destroy
  FormatTime, vSelectedDate0, %vSelectedDate0%, yyyy-MM-dd ddd
  Send %vSelectedDate0%
return

; =========================================================
; Templates for Calender Function in different date formats
;   
;   DD. MMMM YYYY   -   17. Januar 2006   -   DIN 5008 (German alphanumeric)
;   DD. MMM. YYYY   -   17. Jan. 2006   - DIN 5008 (German alphanumeric short)
;   YYYY-MM-DD      -   2006-01-17   -   ISO 8601 (standard/extended Format)
;   YYYYMMDD        -   20060117   -   ISO 8601 (Basisformat)
;   YY-MM-DD        -   06-01-17   -   ISO 8601/2000 (Shortformat old)
;   YYMMDD          -   060117   -   ISO 8601/2000 (Shortformat IT)
;   DD.MM.YYYY      -   17.01.2006   -   DIN 5008 (German optional writing)
;   DD.MM.YY        -   17.01.06   -   DIN 5008 (German optional writing short)
;   DD/MM/YYYY      -   17/01/2006
;   DD/MM/YY        -   17/01/06
;   DDMMYYYY        -   17012006
;   DDMMYY          -   170106
;   
; =========================================================
;Key: Shift+CTRL+F9 -> GUI Selection for Date in a spec. Format


^+F9:: ;; Paste Specific Date in format
   SendInput % CalendarDate()
return

CalendarDate()
{
   Global F_Date
   Global FormatChoice
   Gui, 3:Add, Text, x6 y10 w130 h20,Enter the date :
   Gui, 3:Add, DateTime, x6 y25 w130 h20 vF_Date,
   Gui, 3:Add, Text, x6 y50 w130 h20,Choose your format :
   Gui, 3:Add, DropDownList, x6 y65 w130 h180 vFormatChoice, yyyy-MM-dd|dd.MM.yyyy||dd. MMMM yyyy|dd. MMM. yyyy|yyyyMMdd|yy-MM-dd|yyMMdd|dd.MM.yy|dd/MM/yyyy|dd/MM/yy|ddMMyyyy|ddMMyy|dddd
   Gui, 3:Add, Button, x6 y95 w60 h20 Default,&OK
   Gui, 3:Add, Button, x76 y95 w60 h20,&Cancel
   Gui, 3:Show, x562 y225 h125 w146, Date
   WinWaitClose, Date, Enter the date
   Return TD_RDate

   3GuiEscape:
   3ButtonCancel:
   3GuiClose:
      Gui, 3:cancel
      Gui, 3:Destroy
      TD_RDate = 0
   return

   3ButtonOK:
      Gui, 3:submit
      Gui, 3:Destroy
      FormatTime, TD_RDate, %F_Date%, %FormatChoice%
   return



Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 42 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group