#Include file "test.ahk" cannot be opened. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
GollyJer
Posts: 69
Joined: 19 Sep 2015, 19:33
Contact:

#Include file "test.ahk" cannot be opened.

29 Apr 2018, 18:04

I have the following test file in Standard Lib.

Code: Select all

MsgBox, "hi from test.ahk"

test_msg() {
  MsgBox, % "hi from test_msg()"
}
From another script, if I...
- call test_msg I get the message box. I assume this means the Standard Lib functionality is working.
- #Include c:/path/to/lib/test.ahk I get the message box.
- #Include test.ahk I get #Include file "test.ahk" cannot be opened.

From the Include documentaion it seems #Include <libname> should work.

What am I missing?
User avatar
Masonjar13
Posts: 1555
Joined: 20 Jul 2014, 10:16
Location: Не Россия
Contact:

Re: #Include file "test.ahk" cannot be opened.  Topic is solved

29 Apr 2018, 18:25

#include <liborfunction> does work. #include C:/path/to/file.ahk and #include <file> are two separate syntaxes. When using <>, it looks in a standard library location. When you don't use them, it assumes a relative path based on the scripts directory, or a full, exact path. So, if you use #include <test>, it will work.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
GollyJer
Posts: 69
Joined: 19 Sep 2015, 19:33
Contact:

Re: #Include file "test.ahk" cannot be opened.

29 Apr 2018, 19:49

Wow. I must have tried everything except literally putting the <> around the name.

Why can't AHK be more standard here?
It would be more obvious if you could just #Include filename. :)

Thanks Masonjar13 :!:
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: #Include file "test.ahk" cannot be opened.

30 Apr 2018, 00:49

#include <headername> is standard C++ syntax. Using #include libname for this purpose would be less standard, not more. ;)

#Include FileOrDir accepts a full or relative path, including extension, whereas #Include <LibName> accepts the equivalent of a function name (which works the same way as function auto-includes).

#include lib_func would have to first search for the file literally named "lib_func" in the working directory, then "lib_func.ahk" in each Lib, then "lib.ahk" in each Lib, until one is found. #include <lib_func> skips the first one, because it can be clearly distinguished from #include filename.
User avatar
GollyJer
Posts: 69
Joined: 19 Sep 2015, 19:33
Contact:

Re: #Include file "test.ahk" cannot be opened.

30 Apr 2018, 09:50

lexikos wrote:#include <headername> is standard C++ syntax. Using #include libname for this purpose would be less standard, not more. ;)
Ha! Makes sense. I've been writing React/ES6 Javascript and Python for the last year. I've never even looked at C++ code beyond perusing your AHK GitHub repo. :)
lexikos wrote: #Include FileOrDir accepts a full or relative path, including extension, whereas #Include <LibName> accepts the equivalent of a function name (which works the same way as function auto-includes).
Makes sense! This is a simple and clear explanation. Maybe add to the docs? Is there a way for users to contribute pull requests to the docs?

Thanks as always!
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: #Include file "test.ahk" cannot be opened.

03 May 2018, 02:03

Exactly which part of the explanation in my post is not already written, simply and clearly, in the documentation?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: dipahk and 240 guests