Define global variables with inputbox, then insert with other macro Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
flw
Posts: 3
Joined: 14 Nov 2017, 04:00

Define global variables with inputbox, then insert with other macro

14 Nov 2017, 06:00

Hi,

recently I started to use autohotkey and it is fantastic. Now I have a new idea and as a beginner would like your input on how to write it correctly:

My idea is as follows:

Code: [Select all] [Download] GeSHi © Codebox Plus

;Test
#1::
InputBox, variable1, Reference, Please enter a reference range,,,,,,,,%variable1% ;e.g., "900-000"
InputBox, variable2, Counter, Please enter a counter start,,,,,,,, ;e.g., "3"
;MsgBox, %variable1%%variable2% ; e.g., "900-0003"
return

#2::
SendInput {Backspace} %variable1%%variable2% ; e.g., "900-0003"
variable2++
return



1. How do I pass the variables between the two macros? I cannot transfer the documentation for global variables (https://autohotkey.com/docs/Functions.htm#Global) to my example.
2. As shown above, I would like to populate the Inputbox with the current string stored for variable1 - do I need to error-proof this somehow if variable1 may be empty or is it just empty then?
2b. Would it be possible to store the selected string as variable1, if any string is selected when #1 is pressed?

I am grateful for your suggestions. :D
User avatar
evilC
Posts: 3600
Joined: 27 Feb 2014, 12:30

Re: Define global variables with inputbox, then insert with other macro

14 Nov 2017, 06:36

It works exactly as you described?
The first time you hit #1, variable1 is empty, so the InputBox is empty.
The 2nd time you hit #1, the value that you entered the 1st time is pre-populated.
If you want to have a default value for variable1 the 1st time you run the script, then set the variable in the auto-execute section

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

flw
Posts: 3
Joined: 14 Nov 2017, 04:00

Re: Define global variables with inputbox, then insert with other macro

14 Nov 2017, 07:07

Yes, it works. It seems I overcomplicated it in my mind. Very intuitive in hindsight. Thank you.
But would it be possible to populate variable1 with the highlighted text if it is empty, before showing the Inputbox for the first time?

Example:

I start AHK.
Variable1 is empty.
I select the string "ABCD".
I press the first button.
The Inputbox (as described above) is shown, populated with "ABCD".
I enter "ABCDE".

...

I press the first button for the second time.
The Inputbox (as described above) is shown, populated with "ABCDE".
User avatar
evilC
Posts: 3600
Joined: 27 Feb 2014, 12:30

Re: Define global variables with inputbox, then insert with other macro

14 Nov 2017, 07:27

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

flw
Posts: 3
Joined: 14 Nov 2017, 04:00

Re: Define global variables with inputbox, then insert with other macro  Topic is solved

14 Nov 2017, 09:10

Nice, thank you.

Here is my final code:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
evilC
Posts: 3600
Joined: 27 Feb 2014, 12:30

Re: Define global variables with inputbox, then insert with other macro

14 Nov 2017, 11:56

This code seems pointless:

Code: [Select all] [Download] GeSHi © Codebox Plus

	AltCB2 = %Clipboard%
variable1 := AltCB2 ;store clipboard into variable1
AltCB2 := ;empty alternative clipboard


Why not just

Return to “Ask For Help”

Who is online

Users browsing this forum: Bad husband, Bing [Bot], Class1, DarkKitten, geekgarage, Rastahammer and 44 guests