Jump to content

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"


MsgBox(0,"",$variable1)

 

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.

David

Edited by david1337
Link to comment
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
Link to comment
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
.......
Next

"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
Link to comment
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 !

Bill 

Link to comment
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])
Next

;read example below here:

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

For reading you could also do something with "IniReadSection"

Link to comment
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
Link to comment
Share on other sites

Have a look at:

_ArrayToString

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:

StringSplit

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

Link to comment
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.AddCode(BinaryToString(InetRead("https://raw.githubusercontent.com/douglascrockford/JSON-js/master/json2.js")))
$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
    $b.push($a[$i])
Next
;~ 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"))

 

Link to comment
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)

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

_ArrayDisplay($aString_to_array)

 

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

×
×
  • Create New...