cag8f Posted December 3, 2010 Share Posted December 3, 2010 Hey all. I'm getting a curious error when I try to use #include in a certain way. Here is File1.au3 #include <file.au3> MsgBox ( 0, "", "hi") Exit When I run File2.au3 File2.au3 #include <File1.au3> Exit I get the "hi" message as expected. Then I modify File2 to: File2.au3 $tp = 0 If $tp = 0 Then #include <File1.au3> EndIf Exit It does not work, and I get an error message: >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\temp\File2.au3" C:\Program Files (x86)\AutoIt3\Include\file.au3 (47) : ==> "If" statement has no matching "EndIf" statement.: Func _FileCountLines($sFilePath) >Exit code: 1 Time: 0.212 The error message is pointing to the built in include file 'file.au3.' But I've been using this file for the past few weeks without any problem. I looked at the file.au3 script and it didn't seem overtly corrupted. Regardless, it is probably not due to any problems with file.au3. Any thoughts on what is happening? Link to comment Share on other sites More sharing options...
Tankbuster Posted December 3, 2010 Share Posted December 3, 2010 (edited) //edit: if you add #include <File1.au3> $tp = 0 If $tp = 0 Then #include <File1.au3> EndIf consolewrite(1) Exit it works (I got no idea why?) but anyway the exit in the file1.au will stop your script. Maybe you should put it in a separate function like: #include <File1.au3> $tp = 0 If $tp = 0 Then _file1_msgbox() EndIf Exit #include <file.au3> func _file1_msgbox() MsgBox ( 0, "", "hi") EndFunc Edited December 3, 2010 by Tankbuster Link to comment Share on other sites More sharing options...
cag8f Posted December 3, 2010 Author Share Posted December 3, 2010 I think you understood it correctly. I'm kind of trying to nest #include lines. i.e I'm using an #include line to call a program which itself has an #include line. Whether you actually suggested it, or whether you merely inspired me, I moved one #include line to the main calling program and that seemed to solve the problem. Thanks! Link to comment Share on other sites More sharing options...
cag8f Posted December 3, 2010 Author Share Posted December 3, 2010 Is the lesson: If you're calling a program using #include, don't have any #include lines or function definitions in that program? If true, can someone explain the reasoning behind that? If I don't have exactly right, can someone correct me? Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted December 3, 2010 Share Posted December 3, 2010 #includes are UNCONDITIONAL. Put the #include at the top of your script and it will work.If you're calling a program using #include, don't have any #include lines or function definitions in that program?That makes no sense. The content of a #include are just copy-pasted to wherever the #include line is. They are not different "programs".If true, can someone explain the reasoning behind that? If I don't have exactly right, can someone correct me?Of course not. Didn't you take a look at ANY UDF? You are a lazy one. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Tankbuster Posted December 3, 2010 Share Posted December 3, 2010 You refer to the first post. At that time I thought you are totally wrong using the #include "inside" the code. But it came to my mind that I did it some time ago in one of my own scripts. (actually by mistake) So I removed my post, because also the help file gives an example like yours, but not with an:"IF" I found just right now: Suggestion: if you include you own files, I would recommend a file name like: _<coderprefix>_<filename>.au3 same with functionnames. Simply after some month and scripts it is easier to find out id the function is from AUTOIT, UDF or your own file. Not a must, but maybe easier to track later. I guess there are some coding rules, so use them not mine (but take it as an advice) Link to comment Share on other sites More sharing options...
cag8f Posted December 3, 2010 Author Share Posted December 3, 2010 Tankbuster, thanks for your help. I believe I solved my problem. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now