#Include + variables doesn't work Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Scr1pter
Posts: 1275
Joined: 06 Aug 2017, 08:21
Location: Germany

#Include + variables doesn't work

16 Jul 2018, 11:49

Hello,

I created an AHK file which only contains variables (for the future also functions).
In my target script I included that ahk file which contains variables.

The 1st ahk file is named Excel-COM.ahk:

Code: Select all

;Excel-COM
xl          := ComObjActive("Excel.Application") ; Active Excel instance
wb          := xl.ActiveWorkbook  ; Active workbook
ws          := xl.ActiveSheet ; Active worksheet
cellArray   := ["A1", "B1", "C1", "D1"] ; List of cells
cell        := cellArray[i] ; Variable which accesses values of the array
The code of AHK file 2 is:

Code: Select all

#SingleInstance force
#Include Excel-COM.ahk
F5::
ws.Next.Select
return
When running ahk file 2, I expect that pressing F5 will switch to the next workbook.
This works, but only 1 time.
E.g. From Sheet1 to Sheet2.
After pressing F5 again, nothing happens.
When manually selecting a worksheet (e.g. Sheet4) and pressing F5 again, it jumps to Sheet2 again.

If my 2nd code is this, it works perfectly.

Code: Select all

F5::
xl          := ComObjActive("Excel.Application") ; Active Excel instance
wb          := xl.ActiveWorkbook  ; Active workbook
ws          := xl.ActiveSheet ; Active worksheet
cellArray   := ["A1", "B1", "C1", "D1"] ; List of cells
cell        := cellArray[i] ; Variable which accesses values of the array
ws.Next.Select
return
Isn't it possible to include variables via include?
I also tried to declare them all as global (in ahk file 1), but the result was the same.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09
User avatar
mshall
Posts: 35
Joined: 13 Jul 2018, 16:42
Contact:

Re: #Include + variables doesn't work  Topic is solved

16 Jul 2018, 12:06

Use #Include in your function.

My test was
variables.ahk
x=1
y=2

testinclude.ahk
F5::
#Include C:\Users\mshall\Documents\HotKey\AutoHotKey\variables.ahk ; direct file path because it didn't like it originally
MsgBox, %x%+%y%

Results:
A message box that says 1 + 2
User avatar
Scr1pter
Posts: 1275
Joined: 06 Aug 2017, 08:21
Location: Germany

Re: #Include + variables doesn't work

17 Jul 2018, 07:20

Yes, now it works.
I thought the correct way was to use #include in the header.
Seems it depends on its use and content.

Thanks.

Regards
Please use [code][/code] when posting code!
Keyboard: Logitech G PRO - Mouse: Logitech G502 LS - OS: Windows 10 Pro 64 Bit - AHK version: 1.1.33.09

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 220 guests