Jump to content

Recommended Posts

Posted

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?

Posted (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 by Tankbuster
Posted

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!

Posted

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?

Posted

#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.
Posted

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)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...