Jump to content

If has no matching EndIf with #include inside of If...


 Share

Recommended Posts

Ok, in SLA-2.0.au3, I have this:

Global $iniloc = @SCRIPTDIR & "\SLA-2.0.ini"

; Right now, check to see if the ini file exists
If Not FileExists($iniloc) Then
 ; If the file doesn't exist, run the cost information gathering thingy
 #include <SLA-2.0-cost_info.au3>
EndIfoÝ÷ Ø   Ý~º&¶«z+`¡ë-¡"ÀÛG(²Ø§~®ß^­è­zºè®Ê.¶åw·²Ö­x-«jº^Ú®¢Ð´÷`èréÛԶاÍ=ÙD$ADÓÝzÉ-¢=Øúèç-³OvjëhÛ÷ÓÝr$ÞÓÝ´÷f®¶­Ýì^ªê-üJ뢴­të­ªê-Ov.éí±©ÝIëmx,ÓÝHòDM=Ø7¬Ú)ÓÝ®ÞrÛ4÷m´ÓÝ,
´jíêºBÓݡ˦z{ljwRzÛb4÷e

I've attached full copies of both script files, where you will discover the error if you attempt to run the main file, not the included one.

Link to comment
Share on other sites

#include <>
isn't conditional.
Odd, I currently use it on lines 474-493 in the main script as seen below:

Case $btnRun2
      If $error <> 1 Then
       GUISetState(@SW_HIDE, $frmConfirm)
       
       WinWaitNotActive("Syte Line Automation", "", 10)
       
       $consisting = StringReplace($consisting, @CRLF, @LF)
       $exnotes = StringReplace($exnotes, @CRLF, @LF)
       
       ;BlockInput(1)
       #include <SLA-2.0-include.au3>
       
       WinMinimizeAll()
       
       new()
       
       ExitLoop
      Else
       MsgBox(16 + 4096, "Error", "An item is N/A that cannot be N/A. You must correct this issue to continue.")
      EndIf

Never once have I ever had an issue with that...

Link to comment
Share on other sites

  • Developers

Still: The included file is inserted at the place where the #include is located BEFORE the execution of the script begins.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Still: The included file is inserted at the place where the #include is located BEFORE the execution of the script begins.

What do you mean before the execution of the script begins? Doesn't the execution of the script begin on line 1? Or does it begin once a GUI has been defined? How can I tell where the execution of the script actually begins?

Wouldn't "Global $iniloc = @SCRIPTDIR & "\SLA-2.0.ini"" begin the script, assuming that the others are just fluff?

Link to comment
Share on other sites

What about doing something like this instead?

#include <SLA-2.0-cost_info.au3>

Global $iniloc = @SCRIPTDIR & "\SLA-2.0.ini"

; Right now, check to see if the ini file exists
If Not FileExists($iniloc) Then
 ; If the file doesn't exist, run the cost information gathering thingy
 rw()
EndIf

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

What about doing something like this instead?

#include <SLA-2.0-cost_info.au3>

Global $iniloc = @SCRIPTDIR & "\SLA-2.0.ini"

; Right now, check to see if the ini file exists
If Not FileExists($iniloc) Then
 ; If the file doesn't exist, run the cost information gathering thingy
 rw()
EndIf
Thought about it, but it wouldn't work unless I radically rearranged a whole lot of code... which I'm not in the mood to do at this moment in time. I'd have to radically rearrange things because you can't define functions inside of functions, which as you may notice, there are functions defined inside of Cost Info.au3. I need to execute that script right off the bat, if the file doesn't exist.

Jos, I tried moving the script around to after the GUI is first displayed, and everything, and it still errors out... I'm really confused by what you meant by "the start of the script."

Edited by Tasmania
Link to comment
Share on other sites

Jos, I tried moving the script around to after the GUI is first displayed, and everything, and it still errors out... I'm really confused by what you meant by "the start of the script."

What I think he means is that AutoIt #includes everything before your scripts are processed.

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

Maybe this example will explain what's happening.

#include doesn't get parsed when it's line is reached in the script, it's parsed before the interpreter even starts to execute the script.

Say, you're trying to use the following code (pretend we have these three files):

include1.au3

include2.au3

mainscript.au3

include1.au3:

Func MyFunction()
  MsgBox(0, 'Include 1', 'This is MyFunction from include1')
EndFunc

include2.au3:

Func MyFunction()
  MsgBox(0, 'Include 2', 'This is MyFunction from include2')
EndFunc

mainscript.au3:

$random = Random(1, 2, 1)
If $random = 1 Then
  #include <include1.au3>
Else
  #include <include2.au3>
EndIf
MyFunction()

Now, that looks almost like it would work, correct? If $random is 1, it loads include 1, and defines MyFunction to say whatever, and same if $random is 2. In a PHP script (a lot of the people expecting this behaviour are PHP users) this is perfectly logical, but in AutoIt, it's completely illogical. The reason being is this. In PHP, it would go through that script, line by line, doing what you expect. What AutoIt does is this:

1. Read script (not execute), replace all #include statements with files, check for horrible syntax errors, etc.

2. Execute script.

So my example script above, becomes the following, before AutoIt even starts to interpret it:

$random = Random(1, 2, 1)
If $random = 1 Then
Func MyFunction()
  MsgBox(0, 'Include 1', 'This is MyFunction from include1')
EndFunc
Else
Func MyFunction()
  MsgBox(0, 'Include 2', 'This is MyFunction from include2')
EndFunc
EndIf
MyFunction()

Which throws an error once it starts to be interpreted because for one thing, you cannot define functions inside an If statement (which seems to be the root of your problem) and besides that, I have two function definitions for the same function.

Hope that clears some stuff up.

Link to comment
Share on other sites

  • Developers

What do you mean before the execution of the script begins? Doesn't the execution of the script begin on line 1? Or does it begin once a GUI has been defined? How can I tell where the execution of the script actually begins?

Wouldn't "Global $iniloc = @SCRIPTDIR & "\SLA-2.0.ini"" begin the script, assuming that the others are just fluff?

This is the process:

- Pre-processing phase: the Script is read line by line and interpreted and tokenized and when an #Include statements is encountered its inserted.

- Execution: The tokenized code is ran.

So yes, #include statements are done in the pre-processing phase before the real execution of the script takes place.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Which throws an error once it starts to be interpreted because for one thing, you cannot define functions inside an If statement (which seems to be the root of your problem) and besides that, I have two function definitions for the same function.

Hope that clears some stuff up.

I'm not 100% sure, but I think you can define function inside an "If".

But once the function was already defined (from your example, if "If" turns out to be true), you can no longer redefine the same function (from your example, if "If" turns out to be false). I think that's was causing the error, but as I said, I'm not 100% sure.

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

  • Developers

I'm not 100% sure, but I think you can define function inside an "If".

But once the function was already defined (from your example, if "If" turns out to be true), you can no longer redefine the same function (from your example, if "If" turns out to be false). I think that's was causing the error, but as I said, I'm not 100% sure.

I am 100% sure that you cannot define Func's inside If-EndIF :)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I am 100% sure that you cannot define Func's inside If-EndIF :)

Hehe, okay, well I guess I'll just rearrange my code then!

By the way, after rearranging, I just put all of it in a function of it's own and took the functions out and it worked... I do come from programming PHP... actually I program PHP pretty in-depth, so I suppose that's why this just doesn't make sense to me ;)

Link to comment
Share on other sites

I'm not 100% sure, but I think you can define function inside an "If".

Nope. Fails pretty solidly:

If True Then
    Func _Test ()
        ConsoleWrite("Debug: running _Test()..." & @LF)
    EndFunc   ;==>_Test
    _Test ()
EndIf

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I am 100% sure that you cannot define Func's inside If-EndIF :)

Thanks! ;)

Hehe, okay, well I guess I'll just rearrange my code then!

By the way, after rearranging, I just put all of it in a function of it's own and took the functions out and it worked... I do come from programming PHP... actually I program PHP pretty in-depth, so I suppose that's why this just doesn't make sense to me :P

lol, I came from PHP background too and have been pushing AutoIt to do things it doesn't allow to be done too :P

[font="Georgia"]Chances are, I'm wrong.[/font]HotKey trouble?Stringregexp GuideAutoIT Current Version

Link to comment
Share on other sites

Thanks! :)

lol, I came from PHP background too and have been pushing AutoIt to do things it doesn't allow to be done too ;)

Hehehe... I like them both, and they both seem to be pretty powerful... but I guess I'm just a whole lot more familiar with PHP than this. Which, I suppose, is to be expected.
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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