Automatically calculate previous Tues/Fri with an override

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vernanonix
Posts: 1
Joined: 01 Aug 2021, 20:56

Automatically calculate previous Tues/Fri with an override

01 Aug 2021, 21:08

So I'm trying to program something for my job. Specifically, I need some code that will, when run, update a variable that the date of the last Tuesday or Friday, whichever if latest. (DOAI in my code below.) And I have that part working. However, I'm trying to add an override as well so we can manually enter a date should the most recent Tuesday or Friday rule not apply. Whenever I run the code below, it spits out the current date rather than the variable entered at the beginning. I'm not really sure why though.

I'd also really like to be able to have this update everything I run the actual code this is supposed to be paired with so I don't have to relaunch the code every Tuesday and Friday, but I'm not super certain where to start with that.

Here's the code. It's not clean, but it 90% functions the way I need it to at least. Bench is only being printed for debugging purposes:

Code: Select all

override=1
bench=0
DOAI=07302021

if override=1
	bench = 7
else if (A_WDay=3 || A_WDay=6)
	bench = 0	
else if (A_WDay=4 || A_WDay=7)
	bench = 1
else if (A_WDay=5 || A_WDay=1)
	bench = 2
else if (A_WDay=2)
	bench = 3


if override = 0
	DOAI := A_Now
	DOAI += -bench, D
	FormatTime, DOAI, %DOAI%, MMddyyyy
Return


^!`::
Send, %bench%
Send, {enter}               
Send, %DOAI%
return
Any help is much appreciated.
User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Automatically calculate previous Tues/Fri with an override

01 Aug 2021, 21:44

See how blocks are enclosed in braces: If.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Lamron750 and 242 guests