Sign in to follow this  
Followers 0
Eekhoorn

Script While/Do

8 posts in this topic

Hey, I got this script but it's not working like it should be. The sub scripts are perfect(and simple:)).

Here is the code:

WinWaitActive("Untitled - Notepad")

#include <script1.au3>
#include <script2.au3>
#include <script3.au3>
#include <script4.au3>

dim $aRun[4] = ["script1.au3", "script2.au3", "script3.au3", "script4.au3"] 
$rand = random(1,4,1)

dim $iCount

$iCount = 0

while 1
    if $iCount < 100 then run($arun[$rand]) 
    $iCount =  $iCount + 1
    
    
WEnd

Really need help, thanks in advance!

It works well actually, but it doesn't repeat...

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The index of an array starts with 0. So you have to change the random statement to generate numbers between 0 and 3 for an array with 4 elements:

$rand = random(0,3,1)
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

The index of an array starts with 0. So you have to change the random statement to generate numbers between 0 and 3 for an array with 4 elements:

$rand = random(0,3,1)

Changed that, but still the same problem.. It gives no error and it doesnt shut done btw

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I've reformated your script a bit. What you need is some error checking. Run the script and post what you get in SciTe.

#include <script1.au3>
#include <script2.au3>
#include <script3.au3>
#include <script4.au3>

Global $aRun[4] = ["script1.au3", "script2.au3", "script3.au3", "script4.au3"] 
$iRand = random(0,3,1)
Global $iCount = 0
WinWaitActive("Untitled - Notepad")
While 1
    if $iCount < 100 then 
        $iResult = run($aRun[$iRand])
        ConsoleWrite("Script " & $aRun[$iRand] & " executed. @error = " & @error & ", @extended = " & @extended)
    Else
        Exit
    Endif
    $iCount =  $iCount + 1
WEnd
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

#5 ·  Posted (edited)

I've reformated your script a bit. What you need is some error checking. Run the script and post what you get in SciTe.

#include <script1.au3>
#include <script2.au3>
#include <script3.au3>
#include <script4.au3>

Global $aRun[4] = ["script1.au3", "script2.au3", "script3.au3", "script4.au3"] 
$iRand = random(1,4,1)
Global $iCount = 0
WinWaitActive("Untitled - Notepad")
While 1
    if $iCount < 100 then 
        $iResult = run($aRun[$iRand])
        ConsoleWrite("Script " & $aRun[$iRand] & " executed. @error = " & @error & ", @extended = " & @extended)
    Else
        Exit
    Endif
    $iCount =  $iCount + 1
WEnd

Thanks!

but $iResult is not declared and gives an error. dim $iResult doesnt work, neither does global $iResult. Any solutions ?

edit: rand was declared, but we used iRand, changed that! no errors anymore now

edit2: You know, he isn't doing the loop at all, it just runs script1, then script2 etc..

Edited by Eekhoorn

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

BTW: I didn't correct the error with the wrong index. The correct version is:

#include <script1.au3>
#include <script2.au3>
#include <script3.au3>
#include <script4.au3>

Global $aRun[4] = ["script1.au3", "script2.au3", "script3.au3", "script4.au3"]
Global $iResult 
$iRand = random(0,3,1)
Global $iCount = 0
WinWaitActive("Untitled - Notepad")
While 1
    if $iCount < 100 then 
        $iResult = run($aRun[$iRand])
        ConsoleWrite("Script " & $aRun[$iRand] & " executed. @error = " & @error & ", @extended = " & @extended)
    Else
        Exit
    Endif
    $iCount =  $iCount + 1
WEnd
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

BTW: I didn't correct the error with the wrong index. The correct version is:

#include <script1.au3>
#include <script2.au3>
#include <script3.au3>
#include <script4.au3>

Global $aRun[4] = ["script1.au3", "script2.au3", "script3.au3", "script4.au3"]
Global $iResult 
$iRand = random(0,3,1)
Global $iCount = 0
WinWaitActive("Untitled - Notepad")
While 1
    if $iCount < 100 then 
        $iResult = run($aRun[$iRand])
        ConsoleWrite("Script " & $aRun[$iRand] & " executed. @error = " & @error & ", @extended = " & @extended)
    Else
        Exit
    Endif
    $iCount =  $iCount + 1
WEnd

same problem, read post above :).

Share this post


Link to post
Share on other sites

edit2: You know, he isn't doing the loop at all, it just runs script1, then script2 etc..

Be aware that #including those files can execute script1, then script2 etc... as you are actually including the code from those included scripts into the main script. Also be aware that Run() executes files that are executable so au3 files may not be executable.

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