The following variable name contains an illegal character... but I don't know what it could be

9.7k Views Asked by At

I'm having a problem running my script. I can't for the life of me figure out what the illegal character is.

I have tried putting the string concatenation on separate lines, and I get the same error. I have tried using OneDate and TwoDate instead of Date_1 and Date_2, also to no avail. I have updated AHK, which didn't solve it.

I should note that I am using both MonthCal and DateTime Gui control to get these dates, then formatting them with FormatTime. Another error I have noticed, which may provide a clue, is that no matter what dates I pick in the date controls, I get 2017-Sep-01 as the output. It's possible that no values are coming through from the controls, and the FormatTime function is using today's date because the variables it's attempting to work on are blank / don't exist.

Other than than, generally I like to be more descriptive in my questions, but in this case, I think all I can say is: "Help?"

enter image description here enter image description here

1

There are 1 best solutions below

2
On BEST ANSWER

When you use the expression assignment method := you shouldn't use %. Instead you should write Output := Output Date_1 "_to_" Date_2. When you do use % with expression assignment Autohotkey dereferences the variable and tries to treat OtherDescription--2017... as a variable name and - is not a legal character for an Autohotkey variable.

The following example will help make it more clear:

astring := "some text"
output = a
Output := %Output%STRING
MsgBox % Output

The MsgBox will show "some text". This happens because Autohotkey dereferences %Output% to "a" and then assigns to it the value of astring variable (it concatenates "a" and "STRING" and then looks for a variable called astring).