If () comparison not working. What am I doing wrong?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PaulLeavitt
Posts: 58
Joined: 21 Oct 2014, 10:04

If () comparison not working. What am I doing wrong?

18 Nov 2014, 16:38

So I'm performing what I thought would be a simple if statement, and I absolutely cannot get it to work, and it's probably because I'm missing a pair of """"s or something similarly simple. Here's my code:

Code: Select all

If winactive("ahk_class TROLineDlg")
	{
		ControlGetText, DateinputIllegal, TmtDBDateDialog1				;Get Date from date field
		Msgbox Illegal text is %DateinputIllegal%
		StringReplace, CorrectedDateInput, DateinputIllegal, /,,All			;Remove backslashes from date
		Msgbox Corrected date is %CorrectedDateInput%
		StringLeft, ShortenedCorrectedDateInput, CorrectedDateInput, 4		;Grab first four characters of original date input (Farther up in code)
		StringLeft, ShortenedCorrectedRODate, CorrectedRODate, 4		;Grab first four characters of incorrect date for analysis
		msgbox Shortened original date is "%ShortenedCorrectedRODate%" `nShortened date is "%ShortenedCorrectedDateInput%"								;Print values to screen
		Sleep 1500
		If (ShortenedCorrectedDateInput != %ShortenedCorrectedRODate%)	;Compare value of variables	
		{
			Msgbox,4, Warning, Dates don't match. `nShortenedCorrectedRODate = %ShortenedCorrectedRODate% `nShortenedCorrectedDateInput = %ShortenedCorrectedDateInput% `nCommencing date change, 4
			ifmsgbox No
				Break
			TrayTip,, Corrected RO Date %CorrectedRODate% 
			Sleep 1000
			ControlGetFocus, FocusReturnFunction,
			TrayTip, Update, Starting focus was %FocusReturnFunction%.
			Sleep 1000
			ControlFocus, TmtDBDateDialog1
			Sleep 1000
			ControlSend, TmtDBDateDialog1, %CorrectedRODate%, A
			Sleep 1000
			ControlFocus, %FocusReturnFunction%
			ControlGetText, Dialog2Date, TmtDBDateDialog1
			TrayTip, Update, Dialog 2 Date: %Dialog2Date%
			Sleep 1000
		}
The If (ShortenedCorrectedDateInput != %ShortenedCorrectedRODate%) line is what's giving me trouble.

Higher up this scrip is is pulling a date from one input box, which has the form "11/12/14," and stripping it of it's backslashes, resulting in "111214". Then this section of script is supposed to check another date box, which is unfortunately in the form of "11/18/2014" (today). So in order to do the comparison I stripped it of it's slashes, and then using LeftString Stripping both variables down to their first four characters, so they read "1112" and "1118." So far so good. It changes the date, and then should check again.

Here's where I run into trouble. Even though both variables have the same number (and the MsgBox tells me so), it still thinks that they're not equal. I'm probably just missing a piece of syntax, right?
Thanks!
Paul
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: If () comparison not working. What am I doing wrong?

18 Nov 2014, 16:46

Remove the % around the var as you are derefing it that way, making the number it holds the var to be checked
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
PaulLeavitt
Posts: 58
Joined: 21 Oct 2014, 10:04

Re: If () comparison not working. What am I doing wrong?

09 Dec 2014, 13:31

So it should read like this :If (ShortenedCorrectedDateInput != ShortenedCorrectedRODate)?

So if I'm understanding you correctly, variables can handle the "/" symbol? Are there any exceptions? Or am I completely misunderstanding the documentation, and is "/" simply not allowed in variable names?

Thanks!
Paul
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: If () comparison not working. What am I doing wrong?

09 Dec 2014, 14:23

Yes and / is simply not allowed in variable names
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
User avatar
PaulLeavitt
Posts: 58
Joined: 21 Oct 2014, 10:04

Re: If () comparison not working. What am I doing wrong?

19 Dec 2014, 10:39

Ok, that all makes sense. So if I may, I have one other question regarding string replace. I need to detect if the user inputs a six digit (like 12/05/14), an eight digit (12/05/2014), or a five digit (15/5/14). In any case what I need is for the day of the moth (05) to be two digits. So if the user doesn't input a '0,' how can I use string replace (or anything else) to detect that?
Thanks!
Guest

Re: If () comparison not working. What am I doing wrong?

19 Dec 2014, 10:49

You can also not use StringReplace or RegExReplace - you can probably have a 4 digit input as well

Code: Select all

list=1/05/14,12/05/14,12/05/2014,15/5/14 ; 4 examples to check

Loop, parse, list, CSV
	{
	 StringSplit, dd, A_LoopField, /
	 date:=SubStr("0" dd1, -1) "/" SubStr("0" dd2, -1)  "/" SubStr("20" dd3, -3) 
	 MsgBox % date
	}
User avatar
PaulLeavitt
Posts: 58
Joined: 21 Oct 2014, 10:04

Re: If () comparison not working. What am I doing wrong?

22 Dec 2014, 13:55

Your suggestion to limit the number of digits was perfect! I can't believe I hadn't thought of it sooner! So now the user can only input six digits into the date box, and then when they press submit, using StringLen it checks to make sure there are six (in case the user entered four or five), and if there isn't, a dialog pops up explaining in greater detail what the date needs to look like.

Thanks!
User avatar
T_Lube
Posts: 67
Joined: 22 Oct 2014, 00:57

Re: If () comparison not working. What am I doing wrong?

24 Dec 2014, 14:39

If you are using GUI for your form then why not use a DateTime control which provides the standard time format to be used and then you don't have to worry about how the user is giving you information in a different format, the format will be the same based on your coding and removes the human variable aspect of the thing.
User avatar
PaulLeavitt
Posts: 58
Joined: 21 Oct 2014, 10:04

Re: If () comparison not working. What am I doing wrong?

08 Jan 2015, 15:31

Oh, That's a good idea T_Lube! I hadn't thought of doing that. I'll look into implementing that. Thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 266 guests