Jump to content

Script While/Do


Recommended Posts

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...

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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
Link to comment
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
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...