0
votes

I am trying to assign a string to a variable, and then have a hotkey send that variable's value.

I already have a functioning example, where I use f1 to send a text string with some of the automatic Autohotkey variables such as %A_MM% %A_DD% and %A_YYYY% for quick and easy datestamps:

 f1::
     Send, (WTC %A_MM%/%A_DD%/%A_YYYY% %A_Hour%:%A_Min%) :{space} ; press f1
 Return

I tried writing this to test:

 v_test := "testing string in v_test"
 f2::
      MsgBox, %v_test%
 RETURN

But the message box come up blank. Why isn't the message box displaying "testing string in v_test"?

1

1 Answers

1
votes

The variables were never initialized because the variable was not contained within the auto-execute section of the autohotkey script.

To fix this, I had to put the variable declaration at the top of the script, before any RETURNs, EXITs, hotkeys, or hotscripts. I also could have written the variable as GLOBAL, inside of a function, then called the function.