Look for changes in #include files in compiled script

16 posts in this topic

#1 ·  Posted (edited)

Hey guys

I have a script in which I have included some self-made files in the script directory. In these files I have various variables defined.

This is how the file is included and then called in the main script:

#include "Data\test.au3"



test.au3 could contain something like:

$variable1 = "Hello1"
$variable2 = "Hello2"
$variable3 = "Hello3"


Now, if I want to change the value of $variable1 and then run the script, no problem. The script uses the new edited variable.


But If I compile the script, the includes are compiled within the EXE file as intended.
Now, if I change the value of $variable1 and run the EXE file, it doesn't look for my change, since it uses whatever variable that was defined when the script was compiled.


Is there any way that I can have files with variables that changes, and then have a compiled version using these changes, without having to compile again?


Thanks in advance.


Edited by david1337

Share this post

Link to post
Share on other sites

Use normal .txt files with filerread or ini files with iniread instead.

Share this post

Link to post
Share on other sites

#3 ·  Posted (edited)

Hi AutoBert

Thank you for answering.

It's not just that simple is it?

Even though I do a fileread on test.txt which contains my variables, it doesn't just mean that my mainscript now is able to use those variables? Or am I missing something?

Edited by david1337

Share this post

Link to post
Share on other sites

@ l3ill : Thanks, I will try and have a look, to see if I can use your example :)

@ genius257: I actually did give a very simple example. That's all that should be needed according to my question :)


Share this post

Link to post
Share on other sites

Hey l3ill

I am beginning to understand how I can use INI files instead :)

Thank you!

- David

Share this post

Link to post
Share on other sites

#9 ·  Posted (edited)

Hey Bill :)

I got everything working with the INI files now, except one thing!

I have a for/next section which uses all that is included in the $Custom[] variable.

Quick example (working):

Global $Custom[] = ["01_Test", "02_Test", "03_Test", "04_Test", "05_Test", "06_Test", "07_Test", "08_Test", "09_Test", "10_Test"]

For $i = 0 To UBound($Custom) - 1

If FileExists $Test[$i] Then

"01_test", "02_Test" etc. needs to be renamed frequently, so I don't want this part to be inside the actual script as in the above example.

So I tried to solve it with an INI file, just like I did with all the variables:

[Test Section]
Test=["01_Test", "02_Test", "03_Test", "04_Test", "05_Test", "06_Test", "07_Test", "08_Test", "09_Test", "10_Test"]

And the code calls it like this:

Global $Test[] = IniRead($DataFile, "Test Section", "Test", "")

Even though a consolewrite of $Test shows what I expect, I guess I can't do it like this? :)

Edited by david1337

Share this post

Link to post
Share on other sites

On my way out but at quick glance it looks like you are trying to call an array. I would have to test that myself as I have never used ini to hold arrays.

I suggest some error checking to see where your code is skipping and read up on arrays and ini files.

If you don't find it and no one else shows up I will back later...

Good Luck !


Share this post

Link to post
Share on other sites

It does not seem to be possible to write an array to a single value, without some kind of imagination.

Alternatively you could do something like this:

Dim $variable[] = ["a","b","c","d","e"]

IniDelete(@ScriptName&".ini", "variable")

For $i = 0 To UBound($variable, 1)-1
    IniWrite(@ScriptName&".ini", "variable", $i, $variable[$i])

;read example below here:

Dim $variable[1]
    $data = IniRead(@ScriptName&".ini", "variable", $i, Null)
    If $data=="" Then ExitLoop
    $variable[UBound($variable, 1)-1] = $data
    ReDim $variable[UBound($variable, 1)+1]
Until 0
ReDim $variable[UBound($variable, 1)-1]

For reading you could also do something with "IniReadSection"

Share this post

Link to post
Share on other sites

#12 ·  Posted (edited)

Interesting fix ^_^

I was thinking more along the lines of array to string then store in INI and then vice versa when reading.

Perhaps a CSV file or excel would  serve better than ini for array storage?

Edited by l3ill

Share this post

Link to post
Share on other sites

Have a look at:


use a more obscure delimiter than a comma like a pipe or something ' | '     

This will give you a single string that you can save to INI

Then when reading from INI you get the string as a variable and use:


with your pipe delimiter and you have your array back ready to work with.

Share this post

Link to post
Share on other sites
22 minutes ago, l3ill said:

Interesting fix

using ScriptControl and JSON a string conatining any char "should" be able to be saved and loaded like this:

$oSC = ObjCreate("ScriptControl")
$oSC.Language = "JScript"
$oSC.Eval("Array.prototype.Item = function(i){return this[i];};")
$z = $oSC.Eval('new Function("a","return JSON.stringify(a)")')
Dim $a[] = ['a','b','c']
$b = $oSC.Eval("new Array()")
For $i=0 To UBound($a, 1)-1
;~ MsgBox(0, "", $oSC.Eval("JSON.Stringify()"))
MsgBox(0, "", $z($b))

IniWrite(@ScriptName&".ini", "variable", "array", $z($b))

MsgBox(0, "", IniRead(@ScriptName&".ini", "variable", "array", "nope"))


Share this post

Link to post
Share on other sites

I prefer a simpler approach:

  1. Takes an array and makes it a string
  2. Stores the string to an INI file
  3. Reads the string from INI file
  4. Turns it back into an array
#include <Array.au3>
$sFilePath = @ScriptDir & "/tester.ini"

Global $aCustom[10] = ["01_Test", "02_Test", "03_Test", "04_Test", "05_Test", "06_Test", "07_Test", "08_Test", "09_Test", "10_Test"]
Local $sStringArray = _ArrayToString($aCustom, ',')
Local $sStringRepl = StringReplace($sStringArray, ',', '|')
MsgBox(0, "Array to String", $sStringRepl)

IniWrite($sFilePath, "SectionName", "TestKey", $sStringRepl)

$sTestString = IniRead($sFilePath, "SectionName", "TestKey", Default)
$aString_to_array = Stringsplit($sTestString, '|')



Share this post

Link to post
Share on other sites

Hey guys

Thanks for your suggestions!
I am working on the implementation to the actual script right now.
Array to string - to INI - to array, is an interesting approach Bill. That might be the solution :)

Share this post

Link to post
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

  • Similar Content

    • ur
      By ur
      I have recorded a gui installation and modified the au3 file as per my requirement.
      But the problem is, whenever I try to compile the au3 file, I am getting a special character on top of the file.

      Can you suggest how to resolve this as it is appearing everytime during compilation.
      And also I am trying to include a au3 file which is separate folder so I am adding the <..\Library.au3> line.
      It is able to pick that but in that file "Library.au3" there is a file install line.
      FileInstall(".\SendMail.ps1", @ScriptDir & "\SendMail.ps1") Library.au3 is being used by many other codes in the previous folder..
      But the current file is looking for the ps1 file in current folder.
      So is there any option to tell the compiler to pick the dependent files relative to Library.au3 instead of the current code.
    • pedrit0
      By pedrit0
      Hi all.
      I have created an external au3 (a library of functions and vars) that is #included in a main script that i must compile.
      I wish that the content of the library is not merged with the main script when compiling.
      My goal is to keep the ability to modify the library even after the main exe is compiled and that these changes are effective when executing the exe.
      I guess this is not possible using the standard #include method.
      Is there a way to do that ?
      thx a lot :-)
    • xiantez
      By xiantez
      Hey AutoIT Community,
      Just wanted to know if there is a way I can #include all *.au3 files in my script without having to #include each individual .au3 file. For instance, currently I have a laundry list of #includes like this:
      #include <IE.au3>
      #include <Inet.au3>
      #include <AutoItConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <GDIPlus.au3>
      #include <GuiMenu.au3> 
      Would there be a way I could include all of the files above or all  .au3 file in a one liner? That way I do not have to burn up a bunch of lines of code for just my includes.... Your help is greatly appreciated...
    • Miliardsto
      By Miliardsto
      Is there possibility to do it like this?
      Cause as I see compiler doesn't see If statement in case of #include functions.
      It includes these two files all time.
      If $var == True Then #include 'func/funcsByTabs/main_Moda.au3' Else #include 'func/funcsByTabs/main_Others.au3' EndIf  
    • AmarokStudios
      By AmarokStudios
      Good afternoon AutoIt community!,
      I was on Stackoverflow the other day and came across this question: How To Include Files From A Directory. This got me thinking... There has to be a way to do it... After a bunch of research, I wasn't able to find anything. So, I created this UDF to dynamically include every file from the directory. Of course, there are some bugs that I'd like to fix eventually, but for the most part, it works. Simply call the main function (Shown below) right after the rest of the includes before any of your actual code, and the UDF will include all of the au3 files in the specified directory. Without further ado, here is the _includeDir UDF and how to use it!
      Download this code (_includeDir.au3 attached as well) and place it into the directory with your current script. Next, include it in your main file. For now, I'm going to be using one called Example.au3.
      #Include "_includeDir.au3" Now, include whatever else you're going to be including in this script, then call the _includeDir function. NOTE: THIS MUST BE CALLED AT THE TOP OF THE SCRIPT, BEFORE ANY CODE IS WRITTEN! THE FUNCTION FORCES THE SCRIPT TO RESTART SO PUTTING IT LATER IN THE SCRIPT WILL RE-RUN THE CODE!
      #Include "_includeDir.au3" #Include <File.au3> ; Not needed. Just here as an example of a normal script. #Include <Array.au3> ; Not needed. Just here as example of normal script. _includeDir("Directory to Include") MsgBox(0,"Example","This is just an example!") See how the function is called near the top? This is the proper use of the UDF. If you had a folder called "Directory to Include" and had a bunch of .au3 files inside of it, the function would include them all into the Example.au3 script.
      If you run the Example.au3 file now, it will most likely tell you "The directory Things to Include does not exist!". Make sure you enter the name of the directory you're trying to include. Just as a side note, when including files, you should put all of the code in the INCLUDED files inside of functions so they aren't automatically run when included. Variables can be outside of the functions so they are automatically set. Remember, if you have a variable in one included file with the same name of variable in another included file, it will be overwritten with whichever include file was included last.
      Anyways, if you have pointed the directory to include parameter to a folder that exists and run the Example.au3, it will generate a folder called IncludeDirUDF. It will also write a new line inside of Example.au3. It will write the line 
      on line one. Of course, you don't always want it to be written to line one, right? Maybe you want this bit of code to be written on line 3 in order to keep your code organize. Is there a way to do this? Absolutely! Simply add the line number as a second parameter to the function. For example, we want to have this bit of code written on line 3, we would set up our Example.au3 file to look like this.
      #Include "_includeDir.au3" #Include <File.au3> ; Not needed. Just here as an example of a normal script. #Include <Array.au3> ; Not needed. Just here as example of normal script. _includeDir("Directory to Include", 3) MsgBox(0,"Example","This is just an example!") See how we added the 3 to the end of _includeDir? This will tell the function to write the #Include "IncludeDirUDF\loadIncludes.au3" on line 3 of Example.au3. Note, the line HAS TO EXIST in order to be written to it. For example, if your Example.au3 code only has 6 lines, and you specify to be written on line 7, it WILL NOT WORK.
      The code is designed to include and restart in order to process the included files. For some reason, if you want to JUST generate the included file and NOT restart, you can add one more parameter to the code. If you don't want the code to restart, simply set your code up to look like this:
      #Include "_includeDir.au3" #Include <File.au3> ; Not needed. Just here as an example of a normal script. #Include <Array.au3> ; Not needed. Just here as example of normal script. _includeDir("Directory to Include", 3, False) MsgBox(0,"Example","This is just an example!") Note, if you set this last parameter to false, it will simply generate the included file and write to line 3 of Example.au3 (As specified before) and exit before the code reaches the MsgBox() and it will not be displayed.
      The last important thing to note: In order to re-include a different set of files, you must delete the #Include "IncludeDirUDF\loadIncludes.au3" from your main script (In this case, Example.au3) and delete the generated file, IncludeDirUDF. Now you can simply rerun Example.au3 and it will include any the dir with any changes you made to it. Only .au3 files should be in the directory you're trying to include as it will not process the other files and will generate an error.
      I hope this UDF helps somebody out! Comment any questions/concerns you may have and I will try to address them as soon as possible!
      CEO - Amarok Studios