Jump to content

Recommended Posts

Is there any way to skip the execution of a particular block of code like any condition or expression, if the au3 file is included as library.?

Like, in my code I wrote all the functionality as functions and called them in 4 lines.

Now I have another requirement where I need to use the same code but different.So I am importing this code so that I can use these functions.

But the code block which is outside the functions (main code) is being executed when I import the au3 file.Is there any condition to check whether the file is running directly or included in another au3 file as library, so that I can keep the same here.

 

Please suggest if any ideas.

Link to post
Share on other sites
  • Moderators

ur,

Code from an included file is taken verbatim into the main script at the point of the #include directive, so there is no way of directly determining if the code comes from a library or not when the script is running.

If you were a little clearer in your description we might be able to offer some ideas to help - can you show at least some pseudo-code to indicate exactly what you are trying to do.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

You should not have main code in included scripts, but instead put that main code in a function too, so you can decide whether to call it or not. You should have as much code as possible in functions anyway, even in your main script, for the same reason.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to post
Share on other sites

In one file I have written complete logic to build ism files in functions and in the main code.I am calling two custom functions written.

build32();this custom function will compile one particular set of ism 32bit files.
build64();this custom function will compile one particular set of ism 64bit files.

Now, different requirement came where the user should have option to select the ism files(around 9 are there and user will select in the GUI as checkboxes), so I wrote separate au3 file for the selection and calling the above functions based on his selection in GUI.The above lines are in main code should not be executed when I call this in library because I am calling them in the new file based on the user selection.

I don't want to completely remove the lines from main code as we are using that file in different scenario also.If I keep a separate copy of each, then I need to change it every time in both places.Instead, is there any way to surround the above two lines with a if condition.

I tried by keeping a global variable (true or false) and changing it to false in the new code.But it is not taking.

Let me if the files are required, I will attach them.

Link to post
Share on other sites

The thing is that "main" code (code outside of functions) will ALWAYS be executed if/when you include the script. To make your include file more versatile, move that "main" code into a function, or multiple functions, and only call the relevant functions when necessary. That also allows you to have the code inside the function to work with parameters.

If that is somehow not what you need then I guess I'm missing your point. Ideally, write a small reproducer to everyone knows what you are actually doing, or else (indeed) post your code and indicate what's going wrong where.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to post
Share on other sites

Hi Bunny,

I have written all the logic to individual functions and calling the below two functions in the main code.

build32();this custom function will compile one particular set of ism 32bit files.
build64(

This main code we are using it for our regular activities.

Now as a separate task, we are creating GUI for selection of particular items and included this main code as library in that GUI code.

But these two functions are getting called in that also as you said.And we can't remove these 2 lines as it will stop the regular task.

So, if possible so that we can surround the above lines with condition so that it will execute in main task and in the GUI it won't.

Please suggest.

Link to post
Share on other sites
  • Moderators

ur,

Looking at those files, I suggest doing as SadBunny has suggested above: placing the GUI creation code you currently have as the "main script" element of guibuild.au3 into a separate function which you can then call when required.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

Seems like an ideal use of the IsDeclared function.

Declare a variable in your additional au3, say $additional

in your main script something like ...

If Not IsDeclared("additional")
    build32()
Endif

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to post
Share on other sites

I tried by creating a variable in the GUI logic file and used the logic by JohnOne

If Not IsDeclared("additional")

But it is taking the variable as undeclared.

So I created the variable on the line above the include statement.

Now it is working...

All of you guys, Thank you very much.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By PeterVerbeek
      This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.26 contains 214 functions divided into these topics:
      window, desktop and monitor GUI, mouse and color GUI controls including graphical buttons (jpg, png) logics and mathematics include constants string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info Change log and files section  on the PAL website (SourceForge).
      A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
    • By HansHenrik
      here's some PHP code to access AutoIt functions from php: 
      https://github.com/divinity76/autoit_php -
       
      as of writing, only 5 functions are added: MouseMove and MouseClick and _ScreenCapture_Capture and WinWaitActive and Send,

      it also has support for running in Cygwin (which is where i've developed it, but it *should*, in theory, run on normal php-cli for windows as well.), is there any community interest for this? 
       
      example usage
      <?php require_once("autoit.class.php"); $au = new AutoIt(); $au->MouseMove(10, 10, 5); $au->MouseClick("left"); echo "waiting up to 5 seconds for notepad window.."; if($au->WinWaitActive("[CLASS:Notepad]","",5)){ echo "found notepad!\n"; $au->Send("hello from autoit_php"); }else{ echo "timed out while waiting for notepad.\n"; } $imageBinary = $au->_ScreenCapture_Capture(); var_dump(strlen($imageBinary), imagecreatefromstring($imageBinary));  

      (i wanted to use some autoit functions from php-cli, and google wasn't of much help this time..)
    • By Rhidlor
      I was wondering if there was a library or something which provides the capability to Send() to inactive windows, and I know what you're thinking, I could just use ControlSend(); the reason I can't use that in this situation is because I need to hold down keys for specific prolonged periods of time. Also activating the window, Send()ing then de-activating the window isn't really an option here, I need the target window to always be in the background. I've looked around the forums for an adequate amount of time and didn't find anything useful, perhaps because the threads were all 10 years old, nevertheless, if anyone has any suggestions they would be greatly appreciated.
      Thanks!
    • 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 nss
      Hi all,
       
      I am making a program in which I use Bass audio library (with the wrapper for autoit that I found here on forums I think) because of its support for dx effects.
      My problem, though, is that when effects as reverb or echo/delay are added, the channel length is not extended as to fit the tail of the effect, so if the file was really short, you wouldn't even hear the reverb at all.
      I've tried setting the  buffer parameter even to 60k ms, updating the channel length to 60k ms, but nothing makes it so that the effects aren't being cut off.
      I've heard that I could add silence manually to wave files by adding the chr(0) characters, but haven't had any luck doing that, either.
      What I'm doing:
      initialize bass use streamCreateFile to load the wave file with the fx flag and length parameter set to 60000 set the config buffer to 60000 use channel set fx to add dx8 reverb use channel play to play the sound use bass update to update the length to 60000  
      I even tried having only silence in one wave file and tried joining two wave files together, but that didn't work either.
       
      Any help would be very much appreciated.
×
×
  • Create New...