2

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

NotAnAmbiTurner
  • 2,553
  • 2
  • 21
  • 44

1 Answers1

6

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).

Oleg
  • 6,124
  • 2
  • 23
  • 40
  • Thanks :). The confusing thing is that `Output := %Output%STRING` actually works (and IMO is less verbose), which doesn't seem to be really contemplated in the docs, as you're supposed to use (I guess) *either* expression or traditional syntax, not mix them together like that, though I see that capability has been kept in for backwards compatibility. https://autohotkey.com/docs/Variables.htm#Variables. Correct me if I'm wrong / missing something? – NotAnAmbiTurner Sep 05 '17 at 05:57
  • 2
    @NotAnAmbiTurner If by works you mean concatenating then no, it doesn't work. If by works you mean that it does something then yes it does something. I added an example to the answer, I hope everything will be clear now. – Oleg Sep 05 '17 at 06:52