Day selection from drop down menu Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SLickQC
Posts: 3
Joined: 04 Nov 2019, 12:18

Day selection from drop down menu

Post by SLickQC » 22 May 2021, 21:02

I have a working script, the menu opens and you can select from Yesterday to 7 days from now. I was able to make it work, but I would like to know if there is a more elegant/compact way to run my script. I'm using "If" to be able to skip the different values, but there must be an easier way.

Thank you for your help.

Code: Select all

Day = 0 
Menu, menu, Add, - 1 Yesterday, minus1
Menu, menu, Add, Today, Today
Menu, menu, Add, Tomorrow +1, Tomorrow
Menu, menu, Add, Day after Tomorrow +2, AfterTomorrow
Menu, menu, Add, + 3 days, plus3
Menu, menu, Add, + 4 days, plus4
Menu, menu, Add, + 5 days, plus5
Menu, menu, Add, + 6 days, plus6
Menu, menu, Add, + 7 days, plus7
Menu, menu, Show, 300, 410
Menu, menu, Deleteall
return

minus1:  
day = 1
Today:
If (day = 0) ; 
	day = 2  
Tomorrow:
If (day = 0)
	day = 3	
AfterTomorrow:
If (day = 0)
	day = 4
plus3:
If (day = 0)
	day = 5
plus4:
If (day = 0)
	day = 6
plus5:
If (day = 0)
	day = 5
plus6:
If (day = 0)
	day = 7
plus7:
If (day = 0)
	day = 8

Date := A_Now ; todays date
Date += day -2, Days  ; add `n day depending of the menu selection 2= today 3 = tomorrow 1 = yesterday
FormatTime, nDate, %Date%, dd-MMM-yyyy  ; format for program input
MsgBox,,, %nDate%, 1

Rohwedder
Posts: 7672
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Day selection from drop down menu  Topic is solved

Post by Rohwedder » 23 May 2021, 03:12

Hallo,
try:

Code: Select all

Menu, menu, Add, - 1 Yesterday, -1
Menu, menu, Add, Today, 00
Menu, menu, Add, Tomorrow +1, 01
Menu, menu, Add, Day after Tomorrow +2, 02
Menu, menu, Add, + 3 days, 03
Menu, menu, Add, + 4 days, 04
Menu, menu, Add, + 5 days, 05
Menu, menu, Add, + 6 days, 06
Menu, menu, Add, + 7 days, 07
Menu, menu, Show, 300, 410
Menu, menu, Deleteall
return
-1:
00:
01:
02:
03:
04:
05:
06:
07:
or shorter:

Code: Select all

Menu, menu, Add, - 1 Yesterday, -1
Menu, menu, Add, Today, 00
Menu, menu, Add, Tomorrow +1, 01
Menu, menu, Add, Day after Tomorrow +2, 02
Loop, 5
	Menu, menu, Add,% "+ " A_Index+2 " days",% "0" A_Index+2
Menu, menu, Show, 300, 410
Menu, menu, Deleteall
return
-1:
00:
01:
02:
03:
04:
05:
06:
07:
Date := A_Now ; todays date
Date += A_ThisLabel, Days  ; add `n day depending of the menu selection +0 = today +1 = tomorrow -1 = yesterday
FormatTime, nDate, %Date%, dd-MMM-yyyy  ; format for program input
MsgBox,,, %nDate%, 1
SLickQC
Posts: 3
Joined: 04 Nov 2019, 12:18

Re: Day selection from drop down menu

Post by SLickQC » 23 May 2021, 11:35

Thank you very much Rohwedder, I didn't know about the variable "A_ThisLabel", I appreciate the pointer for looping the menu. :thumbup:

Thank you for your time,

Nick.
just me
Posts: 9482
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Day selection from drop down menu

Post by just me » 24 May 2021, 04:24

For this special case:

Code: Select all

#NoEnv
#Persistent
; Create the menu once -----------------------------------------------------------------------------
Items := "Yesterday|Today|Tomorrow|Day after Tomorrow|+ 3 days|+ 4 days|+ 5 days|+ 6 days|+ 7 days"
For Each, MenuItem In StrSplit(Items, "|")
   Menu, CalcDate, Add, %MenuItem%, Calculate
Return
; Ctrl+Shift+m -> show the menu --------------------------------------------------------------------
^+m::
Menu, CalcDate, Show ; , 300, 410
Return
; Menu handler -------------------------------------------------------------------------------------
Calculate:
Date := A_Now ; todays date
Date += A_ThisMenuItemPos - 2, Days  ; add day(s= depending of the menu selection 2 = today 3 = tomorrow 1 = yesterday
FormatTime, Date, %Date%, dd-MMM-yyyy  ; format for program input
MsgBox, 0, Required date:, %Date%
Return
; Esc -> quit --------------------------------------------------------------------------------------
Esc::ExitApp
SLickQC
Posts: 3
Joined: 04 Nov 2019, 12:18

Re: Day selection from drop down menu

Post by SLickQC » 17 Jun 2021, 22:00

That's very cool, much appreciated
Post Reply

Return to “Ask for Help (v1)”