Jump to content
Sign in to follow this  

Look for changes in #include files in compiled script

Recommended Posts

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

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 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

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Fr33b0w
      Func z009() If FileExists("search\009\009.au3") Then #include <search\009\009.au3> EndIf EndFunc This wont work...  Is there any workarround for this or I should do it in a different way?
    • By TrashBoat
      How do i add a path to a file in Include.
      I want my script to get the udf in the same folder as the script/exe:
      Include "@ScriptDir/udf.au3" can this be done?
    • 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.
    • 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 :-)
    • 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...
  • Create New...