Jump to content

Conditional Includes or Workaround


Recommended Posts

Well i'm trying to make a program that uses multiple scripts so can do multiple purposes and don't mix all on a single Au3, first i make the 3 Au3 then i make the main script that handle the Includes with something like this

Switch $CMDline[1]
    Case "names"
        #include "Names.au3"
    Case "Owners"
        #include "owners.au3"
    Case Else
        #include "none"
EndSwitch

after the weird error, i notice that you can't conditionate includes. So, is there a workaround or UDF that i can use without have to compile multiple EXEs?

any advice will help, and thanks

ADS

Link to comment
Share on other sites

i'm just trying to Run the proper Script without to compile multiple Exes or mess with mixes Au3s, also when i'm compiling the main Au3, it includes the others 3 Au3s. there should be a way to do it :D that's why i'm asking for help here

Link to comment
Share on other sites

Well i'm trying to make a program that uses multiple scripts so can do multiple purposes and don't mix all on a single Au3, first i make the 3 Au3 then i make the main script that handle the Includes with something like this

Switch $CMDline[1]
        Case "names"
            #include "Names.au3"
        Case "Owners"
            #include "owners.au3"
        Case Else
            #include "none"
    EndSwitch

after the weird error, i notice that you can't conditionate includes. So, is there a workaround or UDF that i can use without have to compile multiple EXEs?

any advice will help, and thanks

ADS

I don't think you can stop or force any include file being used by having an If statement or any other logic in the script, so you have to create the file as you want it before you compile.

The way you could do it is to have the include replaced by some special text say like this

;common script
 ~~~###include012###~~~
  other stuff
 [code]
 Then you convert this as needed with a relatively simple script which lets you choose the version you want to compile. Maybe it remembers the options and maybe you select the includes you want to be used.
 This second script just has to do something like
 [code]
 $text = FileRead("commonScript.au3")
 $text = StringReplace("~~~###include012###~~~","#include <Names.au3>")
 $hf = FileOpen("temp1.au3",2)
 Filewrite($hf,$text)
 FileClose($hf)
 Run("Aut2exe.exe ...;see help for using Aut2exe.exe to compile scripts.

I

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Well i find out that you can acctually use a #include on a conditional, but it can't have Func inside, so i can run all the Fund First and in the Switch use the core Script. Yeah i know it's alot of work for something stupid, but it's better do that, and don't compile multiple sources codes everytime i make a new version

Link to comment
Share on other sites

Well i find out that you can acctually use a #include on a conditional, but it can't have Func inside, so i can run all the Fund First and in the Switch use the core Script. Yeah i know it's alot of work for something stupid, but it's better do that, and don't compile multiple sources codes everytime i make a new version

Yes, I'm forgetting about recent changes to AutoIt.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

yep it worked like i said, now i have everything on one EXE :D

If $CmdLine[0] <> 0 Then
Switch $CmdLine[1]
    Case "Nombres"
        #include "NombresCore.au3"
    Case "Contador"
        #include "ContadorCore.au3"
EndSwitch

...

#include "NombresFunc.au3"
#include "ContadorFunc.au3"

also i had to delete all the #includes like constanst and add it outside

Link to comment
Share on other sites

yep it worked like i said, ...

No, it didn't.

... now i have everything on one EXE ;)

If $CmdLine[0] <> 0 Then
Switch $CmdLine[1]
    Case "Nombres"
        #include "NombresCore.au3"
    Case "Contador"
        #include "ContadorCore.au3"
EndSwitch

...

#include "NombresFunc.au3"
#include "ContadorFunc.au3"

also i had to delete all the #includes like constanst and add it outside

That made no sense at all.

The entire contents of "NombresCore.au3" and "ContadorCore.au3" are included in the source where you put those lines (inside the Switch Case). How would the compiler know at compile time what your command line parameter was going to be at run time? Have you written a psychic compile function that can read parameters from the future?

:D

Yes, I'm forgetting about recent changes to AutoIt.

What changes are you referring to, martin?

:D

Edited by PsaltyDS
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

No, it didn't.

That made no sense at all.

The entire contents of "NombresCore.au3" and "ContadorCore.au3" are included in the source where you put those lines (inside the Switch Case). How would the compiler know at compile time what your command line parameter was going to be at run time? Have you written a psychic compile function that can read parameters from the future?

:D

:D

What changes are you referring to, martin?

I was referring to the changes that had obviously occurred after my previous post in this thread. These were even larger than I suspected because as you say the compiler now has to either foretell the future or to travel into the past, maybe both. It's all just getting too much for me ;)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

G'day ADS3

You mentioned in one of your earlier posts

"and don't compile multiple sources codes everytime i make a new version"

The trouble is (as I understand it) #include ALLWAYS adds the code from the included file when the file is run or compiled.

So your code

If $CmdLine[0] <> 0 Then
Switch $CmdLine[1]
    Case "Nombres"
        #include "NombresCore.au3"
    Case "Contador"
        #include "ContadorCore.au3"
EndSwitch

...

#include "NombresFunc.au3"
#include "ContadorFunc.au3"

Will ALWAYS compile to

If $CmdLine[0] <> 0 Then
Switch $CmdLine[1]
    Case "Nombres"
        <THE CONETNTS OF "NombresCore.au3">
    Case "Contador"
        <THE CONETNTS OF "ContadorCore.au3">
EndSwitch

...

<THE CONETNTS OF "NombresFunc.au3">
<THE CONETNTS OF "ContadorFunc.au3">

Now your code will still work fine as the lines from "NombresCore.au3" and "ContadorCore.au3" will only be executed when the respective "case" conditions are true.

BUT ALL of the code will be included in the compiled file.

I hope that clarifies things a little.

Link to comment
Share on other sites

Since it's kinda on-topic, is there a discussion about whether the devs will implement include ...selection ? So the compiled executable is smaller and only important/useful code is included ?

I doubt that it will ever be done in AutoIt but what you are asking for is possible using the AutoItWrapper directives.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Since it's kinda on-topic, is there a discussion about whether the devs will implement include ...selection ? So the compiled executable is smaller and only important/useful code is included ?

Things NOT on the ToDo List

http://www.autoitscript.com/trac/autoit/wi...ItNotOnToDoList

Edited by Zedna
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...