Sign in to follow this  
Followers 0
SorryButImaNewbie

Run a bunch of Functions one after an other solutions

16 posts in this topic

Hello guys!

I wanted to make the functions in my program interruptable with the help of the  https://www.autoitscript.com/wiki/Interrupting_a_running_function .

I use OnEventMode and I made the call functions, and everything works fine (I havent filled my functions with the hecessary flag checks during run time yet), after my consultation on the project with my boss he told me that I should also make a function that calls the relevant functions one by one. I wanted to do this with the flags makeing a Function like this:

Func RunAll
$f1run = True
If $f1run = False Then
$f2run = True
EndIF
If $f2run = false Then
$f3Run = True
Endif

;so on
EndFunc

All my $f(number)Run are global and set to false at the beginning of the script. When ever a function is called by setting its variable to True, the function itself sets it back to false after it run.

When I run the code for some reason it doesn't run all the functions, it skips a few (like f1run, then f3run etc) I wasn't sure that my code would work properly anyway since the if starts when the variable of the previous function is false and all of these varibles starts as false alas I don't know if that is the origin of the problem. My most likely hipothesis about this is that the computer real time cloack (not sure if thats the correct name I mean the CPU timer that is also used the generate random numbers for example) is working in a way that its simply return to the not intended part of the code and since the If its checks first is false by default it runs that part.

please asks anything about my code if you need more insight

What do you think? whats your best practice method to develope something like this?

Thank you for your help!

 

Share this post


Link to post
Share on other sites



I think the best way would be if ther is someway to varify if a functions has just "finished", I'm looking for something like that now, but if you have/know something like that pls shoot

Share this post


Link to post
Share on other sites

Wouldn't one single variable be enough to determine if the next function should be run? Or do you need the status of already rn functions?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I don't get it, can you show an example? (I tried to use my already existing variable, but no real reason is bhind that thinking)

Share this post


Link to post
Share on other sites

ohh you mean like a number var that starts from for example 1, and then every functions has a number and after every function run it simply add +1 to that variable causing it to run the next func?

Share this post


Link to post
Share on other sites

I think we need to see more code, as I'm not entirely sure what you are aiming for?

It may be, that the Adlib functions may be of assistance?

It might be, that you need to wait on a return value from a running program?

Run, RunWait, etc etc?


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Set the global variable which determines if the next function is to be run to True, the interruption function then sets it to False and all other functions are not processed then.

Func RunAll
    $bRunFunc = True
    Func1()
    If Not $bRunFunc Then Return
    Func2()
    If Not $bRunFunc Then Return
    Func3()
    If Not $bRunFunc Then Return
    ; Etc
EndFunc

Func Interrupt()
    $bRunFunc = False
EndFunc
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I think we need to see more code, as I'm not entirely sure what you are aiming for?

It may be, that the Adlib functions may be of assistance?

It might be, that you need to wait on a return value from a running program?

Run, RunWait, etc etc?

 

My code is like :

arrays, global variabels at the top amongst them there are the function calling variables, all false

then comes a bunch of functions that are doing actual work. Then a Grp of functions that only sets the variable of a funcrun to true

then a while WEnd loop with a sleep(50) for the "empty run" and checks for the function runs variables

Like this:

;Includes Opts

Global $fTestRun = False ;others like this

;Functions to call (the ones that actually works with the different windows etc)

Func TestRun()
    $fTestRun = True
EndFunc ; This function is called by a button on my form built by ISN AutoIT Studio

While 1 ;üres járat a GUIformnak  + Run flagek kezelése
    Sleep(50)
    If $fTestRun Then
        Test()
    EndIf
        ; the other functions
WEnd

Hope this is okey

(RunWait only works with other programs, I need exactly that but for my functions)

Water

Set the global variable which determines if the next function is to be run to True, the interruption function then sets it to False and all other functions are not processed then.

Func RunAll
    $bRunFunc = True
    Func1()
    If Not $bRunFunc Then Return
    Func2()
    If Not $bRunFunc Then Return
    Func3()
    If Not $bRunFunc Then Return
    ; Etc
EndFunc

Func Interrupt()
    $bRunFunc = False
EndFunc

 

wouldn't this try to run all the functions simulteniously?

 

Also I tried to use the method I described above ($newvar = 1, then adding +1 after every run makeing it call the next function) this caused it to try to run all the functions togeather, wasn' t nice, this is why I'm writing back so slow :D

Edited by SorryButImaNewbie

Share this post


Link to post
Share on other sites

wouldn't this try to run all the functions simulteniously?

No, as AutoIt does not allow multitasking the functions are executed one after the other.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

It tried to run my functions simultaniously 0.o

(I'm going home now from my workplace, I will come back here within an hour from home! thank you for your help so far guys!)

Share this post


Link to post
Share on other sites

Hi!

"No, as AutoIt does not allow multitasking the functions are executed one after the other."

Doesn't this mean that I can just create a function like this:

Func AllFunc
func1()
func2()
func3()
...
EndFunc

Didn't even consider this as an option, I can try it because I cant reach my code from home...

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Your code executes Func1 then Func2 and then Func3.

It tried to run my functions simultaniously 0.o

You can only run external programs simultaniously

Run("program1.exe")
Run("program2.exe")
Run("program3.exe")

Does not wait for the execution of program1.exe to end but starts program2.exe and program3.exe immediately.

Edited by water
1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

This seems to work as you said, thank you!

Share this post


Link to post
Share on other sites

:)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Still I'm somewhat proud of myself that I managed to run multiple functions with some If loops + flags for functions magick :)

Nice to know that the solution was the most basic, most simple thing that I probably should tried first...

Share this post


Link to post
Share on other sites

The most simple results need the most effort :)

1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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