Sign in to follow this  
Followers 0
wazzupseattle

#include files at runtime

13 posts in this topic

I have two au3 files Constants1.au3 and Constants2.au3. In the main program, I have two checkboxes "Choose Contants1.au3" and "Choose Constants2.au3". Depending on which checkbox is checked, I would like to include the corresponding Constants1.au3 or Constants2.au3 file at runtime. ie. I need to do something like this -

If checkbox 1 is selected Then

#include "Constants1.au3"

Else If checkbox 2 is selected Then

#include "Constants2.au3"

EndIf

I tried the above, but it doesn't work. I also tried FileInstall(), but in vain. Anybody has any ideas ?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have two au3 files Constants1.au3 and Constants2.au3. In the main program, I have two checkboxes "Choose Contants1.au3" and "Choose Constants2.au3". Depending on which checkbox is checked, I would like to include the corresponding Constants1.au3 or Constants2.au3 file at runtime. ie. I need to do something like this -

If checkbox 1 is selected Then

    #include "Constants1.au3"

Else If checkbox 2 is selected Then

    #include "Constants2.au3"

EndIf

I tried the above, but it doesn't work. I also tried FileInstall(), but in vain. Anybody has any ideas ?

<{POST_SNAPBACK}>

In your main program, take your constants and define each set as a function.

IE:

Opt ("MustDeclareVars",1)

Global; All variables here to make sure they're in the global scope.


Select
  Case $box1 = $checked and $box2 = $notchecked
      Constants1()
  Case $box2 = $checked and $box1 = $notchecked
     Constants2()
EndSelect

Func Constants1()
; list constant definitions here
End Func

Func Constants2()
; list constant definitions here
End Func

Edit: Minor typo

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I dont think this is possible for a running script. You might be able to make it possible if you are going to use the GUI you have created to write another script.

Edit: Blue Drache's idea is a good one. Creative thinking. Very nice.

Just my thoughts. I could be wrong,

JS

Edited by JSThePatriot

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

In your main program, take your constants and define each set as a function.

IE:

Opt ("MustDeclareVars",1)

Global; All variables here to make sure they're in the global scope.
Select
  Case $box1 = $checked and $box2 = $notchecked
      Constants1()
  Case $box2 = $checked and $box1 = $notchecked
     Constants2()
EndSelect

Func Constants1()
; list constant definitions here
End Func

Func Constants2()
; list constant definitions here
End Func

Edit: Minor typo

<{POST_SNAPBACK}>

I like your idea except that now all the constants from both files will be declared in the same program thereby bloating your exe size, right ? If I could include the appropriate file at runtime, at any point in execution, I'll have constants from one file only. hmm. but your idea is the only feasible one at this point I believe. Thanks!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I like your idea except that now all the constants from both files will be declared in the same program thereby bloating your exe size, right ? If I could include the appropriate file at runtime, at any point in execution, I'll have constants from one file only. hmm. but your idea is the only feasible one at this point I believe. Thanks!

<{POST_SNAPBACK}>

Yes, it does bloat the .exe, but *shrug*. If we were concerned about bloat (as a programming community in general) Microsoft would still be in his mom's garage and we'd still be working with a command line. I just go with what works.

New thought:

#include tells the compiler to include the file at compile time, but the compiler doesn't run the code. How's the compiler supposed to know if the condition is true or not? Also, consider since the user selects which constant file to use.......the compiler is again clueless. You could include a separate INI file with all your variable definitions, but getting the program to read it would be a nightmare.

Dim $file[3]

$file[1] = @scriptdir & "\one.ini"
$file[2] = @scriptdir & "\two.ini"

If $box1 = $checked then Constants($file[1])
If $box2 = $checked then Constants($file[2])



Func Constants($filename)
   $var = IniRead($filename,"","","")
EndFunc

This is a little more elegant, not as bloated, but you have extra files that you're going to need to ship with the .exe. What's now more bloated? The un-alterable .exe, or install directory with the files that can be tampered with?

Edited by Blue_Drache

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

you can store the variables in an ini file and read in the variables at runtime, using a function like this

Func Constants1()
    $trap_sections = IniReadSectionNames("c:\boot.ini")
    For $i = 1 To $trap_sections[0]
        $trap_keys = IniReadSection("c:\boot.ini", $trap_sections[$i])
        For $j = 1 To $trap_keys[0][0]
            Assign($trap_keys[$j][0],$trap_keys[$j][1],2)
        Next
    Next
EndFunc

Share this post


Link to post
Share on other sites

Preprocessor functions are not affected by statements by the compiler (If...Then, Select/Case). However, the contents of the include files will be subject to the statements (I *BELIEVE*, it should in theory, i'll test later).

My suggestions are to just deal with this 'bloating', or, include it in Funcs. Either way, the file size will be the same, or bigger, depending on how many files the end-user will have (bit size and size on disk can be different).

Also, if you use Functions, it makes editing the script more difficult, as there are more lines of code to look at...


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

I use #regions throughout my code, but some people don't, and I don't have access to SciTE other than at home right now...


Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

I use #regions throughout my code, but some people don't, and I don't have access to SciTE other than at home right now...

<{POST_SNAPBACK}>

What are #regions ? I couldn't find help on this in the online documentation or the AutoIt help file :(

Share this post


Link to post
Share on other sites

What are #regions ? I couldn't find help on this in the online documentation or the AutoIt help file  :(

<{POST_SNAPBACK}>

Open the helpfile, click on the Index tab, type in #region or #endregion and they should jump out at you.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Open the helpfile, click on the Index tab, type in #region or #endregion and they should jump out at you.

Dale

<{POST_SNAPBACK}>

I couldn't find help on this in the online documentation or the AutoIt help file. AutoIt help file doesn't have an index for #region. Can someone cut-n-paste the description here.

Share this post


Link to post
Share on other sites

I couldn't find help on this in the online documentation or the AutoIt help file. AutoIt help file doesn't have an index for #region. Can someone cut-n-paste the description here.

<{POST_SNAPBACK}>

You're right of course. Sorry.

It is mentioned in the SciTe documentation in the section on Syntax Folding.

The folding logic folds all Keywords like If-ElseIf-Else-EndIf, Do-Until, While-Wend but also Comment blocks #CS-#CE or block of lines that are commented by a semicolon ;

We also added a special folding keyword #region-#endregion. Any text behind these keywords on the line are considered comments.


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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