Jump to content
Sign in to follow this  
penthi

combining scripts leads to looping

Recommended Posts

penthi

Hi all o/

I am totally new to autoit, but I really *need* a program to do something so I am trying to get the thing done with autoit. Wat I need is a script that opens a number of files in a fixed order. These files are .ebs files, a format used by e-prime which is a program that is used for psychological tests. There are a number of other e-prime users involved in this little "project" and one of them created an autoit script that calls the .ebs files in a fixed (or random) order.

Now say that this scripts opens 5 of these .ebs files in a row. Each of these .ebs files starts with a dialogbox asking for a subjectnumber (and enter) followed by sessionnumber. What I'd like to make is a script that asks for the subject and sessionnumber once in the beginning and then automatically gives in the given values for each of the 5 .ebs files that it runs.

So I started with a script for a loginbox (_loginbox.au3, found somewhere in these forums) and adjusted it so that it asks for subject and sessionnumber instead of loginname and password. So far so good, nothing hard. This script runs well now and after the values have been entered it returns the entered values, it's a nice script.

Now when I combine this with the script to run the .ebs files (created by someone else, also with help from these forums if I'm informed correctly)... mayhem occurs. I gave the combined script a new name obviously but somehow when it's ran it starts looping and opening the 'original' script (scipt to call ebs files in a fixed order.au3), regardless of where I put this script (different folders). The end result is numerous autoit scripts running... apart from the original script (wherefrom i copy pasted part of the code), either the other original script (_loginbox.au3) or the combined script itself also starts looping as besides numerous instances of .ebs files being opened, also loginboxes keep popping up... I really need only one >.>

so...

What could cause this looping? (i.e. why does the combined script call in the original script(s)?) How do I prevent this from happening? And if someone would just happen to have a nifty piece of code ready that could do part of what I want the script to do... that would of course also be welcome ^_^

Share this post


Link to post
Share on other sites
Melba23

penthi,

First, welcome to the AutoIt forums.

The possible reasons for your difficulties are so numerous that it would be foolish to guess. :-) Please post or upload the scripts that you and your colleague have produced - this will give us a better idea of what is going wrong.

To post code, add it to your post between code tags. These are entered as [code ] before and [/code ] after your script (but omit the trailing space - it is only there so the tags display here).

To upload code (useful if the script is really large!), use the 'Browse' and 'UPLOAD' buttons below and to the right of the area where you write your post.

Hope to see something soon.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
penthi

Thank you for your quick reply, Melba!

I found now that the problem arises from my attempts at having the script send the variables from the one original script (loginbox) during the execution of what used to be a different original script.

I'll upload the two scripts separately. eprimeloginbox.au3 is the script that asks for the subject- and sessionnumber. Scripttocallebsfilesinafixed order.au3 is just what it's name implies. Pasting the two into one single script turns out to be no problem, but when I try insert lines to have it send session and subjectnumbers from the first part of the script during the second part of the combined script all goes wrong.

I am new to autoit (the program we now try to control with it, e-prime itself is e-basic based though) and I thought i'd just fiddled around a while with the 'send' function. I tried placing some codelines right before as well as right after the WinWait("E-Run"). I am also not entirely sure on the exact syntax needed, that is: which of the different "variablenames" from the loginboxpart of the script ("subjectnumber' $ret[0], [0], $ssubject etc) I need it to call in to send to the running .ebs file and where to exactly place all the brackets and "'s. To make fun complete I also cannot use a script editor due to ict restrictions on the university (and I can't do it at home cause I can't run e-prime there) and therefore got to figure it all out in notepad.

mmm call me ubern00b I guess ^.^

e_primeLoginBox.au3

script_to_call_ebs_files_in_a_fixed_order.au3

Edited by penthi

Share this post


Link to post
Share on other sites
Melba23

penthi,

OK, this should work - or at least it does with Notepad! You can see where I have added the Notepad lines (marked with <<<<<<<<<<<<<<<<<<<) - all you need to do is to replace them with the commented originals just underneath.

I am assuming that your apps will accept Send normally (alas some do not!) and that you tab between the input boxes and press enter to start the process. If this is not the case, then you need to adjust the keys to send. You may also need to add a Sleep(500) between the Sends to give the app time to react.

I have made 1 change (marked with ##################) to the _GUICreateLogin() function - GUICtrlSetState($username, 256) will not work as the input box is actually called $subjectnumber! The function is a bit OTT for what you want, but it works, so why not use it. :-)

Here is the combined script:

#include <Array.au3>

;(Number of .ebs2 files -- The line of code below refers to a total of 5 ebs2 files to be run)
Dim $i, $iMax = 5
Dim $FileNameArray[$iMax]

Opt("GUICoordMode", " 2")

$ret = _GUICreateLogin("Enter Credentials", "Enter the subjectnumber and session", -1, -1, -1, -1, -1, 10000)
If @error Then
    MsgBox(0, "Error", "Error Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended)
Else
    MsgBox(0, "Credentials Returned", "subjectnumber: " & $ret[0] & @CRLF & "session:  " & $ret[1])
EndIf

For $x = 0 To UBound($FileNameArray) - 1
    $FileNameArray[$x] = '"notepad.exe"'; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
;$FileNameArray[$x] = '"' & @WorkingDir & '\' & ($x + 1) & '.ebs2"'
Next

For $i = 1 To $iMax
    
; Get a random number to act as an index
    $CurrentNumber = Random(0, UBound($FileNameArray) - 1, 1)
    
; Run the selected app
;Run("C:\Program Files\PST\E-Prime 2.0\Program\E-Run.exe /a /m " & $FileNameArray[$CurrentNumber])
    Run($FileNameArray[$CurrentNumber]); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; Wait until the app starts
    WinWaitActive("Untitled -"); <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; WinWait("E-Run")
    
; Here is where you need to send the credentials 
    Send ($ret[0]) ; Send the subjectnumber
    Send ("{TAB}"); Tab to next input
    Send ($ret[1]); Send the session
    Send ("{ENTER}"); Send Enter to accept
    
; Wait for the app ends
    WinWaitClose("Untitled -")  ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; WinWaitClose("E-Run")
    
; Remove this app from the list
    _ArrayDelete($FileNameArray, $CurrentNumber)
    _ArrayDisplay($FileNameArray)
; Check if any are left - is it still an array basically - and exit if not
    If Not IsArray($FileNameArray) Then Exit
Next

;===============================================================================
; Function Name:   _GUICreateLogin()
; Description:   Create a basic login box with Username, Password, and a prompt.
; Syntax:
; Parameter(s): $hTitle - The title of the Form
;                 $hPrompt - The text prompt for the user [Optional] (maximum of 2 lines)
;                 $bBlank - The subjectnumber or session  can be blank. [optional]
;                           Default = False (Blanks are not allowed)
;                 $hWidth - Width of the form [optional] - default = 250
;                 $hHeight - Height of the form [optional] - default = 130
;                 $hLeft - X position [optional] - default = centered
;                 $hTop - Y position [optional] - default = centered
;                 $Timeout - The timeout of the form [optional - default = 0 (no timeout)
;                 $ShowError - Prompts are displayed to the user with timeout [optional]
; Requirement(s):  None
; Return Value(s): Success - Returns an array of 2 elements where
;                                       [0] = subjectnumber
;                                       [1] = session
;                 Failure - Sets @Error to 1 and
;                                @Extended - 1 = Cancel/Exit Button Pressed
;                                          - 2 = Timed out
; Author(s):   Brett Francis (exodus.is.me@hotmail.com)
; Modification(s): GeoSoft
; Note(s): If $hPrompt is blank then the GUI height will be reduced by 30
; Example(s):
;===============================================================================

Func _GUICreateLogin($hTitle, $hPrompt = "", $bBlank = False, $hWidth = -1, $hHeight = -1, $hLeft = -1, $hTop = -1, $timeout = 0, $ShowError = 0)
    If Not $hTitle Then $hTitle = "Login"
    $iGCM = Opt("GUICoordMode", 2);; Get the current value of GUICoordMode and set it to 2
    If StringRegExp($bBlank, "(?i)\s|default|-1") Then $bBlank = False
    If StringRegExp($hWidth, "(?i)\s|default|-1") Then $hWidth = 250
    If StringRegExp($hHeight, "(?i)\s|default|-1") Then $hHeight = 130
    If StringRegExp($hLeft, "(?i)\s|default|-1") Then $hLeft = (@DesktopWidth / 2) - ($hWidth / 2)
    If StringRegExp($hTop, "(?i)\s|default|-1") Then $hTop = (@DesktopHeight / 2) - ($hHeight / 2)
    If Not $hPrompt Then $hHeight -= 30;If $hPrompt is blank then resize the GUI.
    Local $retarr[2] = ["", ""], $Time = 0

    Local $gui = GUICreate($hTitle, $hWidth, $hHeight, $hLeft, $hTop)
    GUISetCoord(4, 0)
    If $hPrompt Then Local $Lbl_Prompt = GUICtrlCreateLabel($hPrompt, -1, 4, 201, 30)
    Local $Lbl_User = GUICtrlCreateLabel("subjectnumber:", -1, 4, 64, 17);44, 64, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    Local $subjectnumber = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21)
    GUICtrlCreateLabel("session:", -($hWidth - 8), 4, 65, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    Local $session = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21, 32);, $ES_session)
    GUISetCoord(($hWidth / 2) - 85, $hHeight - 34)
    Local $Btn_OK = GUICtrlCreateButton("&OK", -1, -1, 75, 25)
    Local $Btn_Cancel = GUICtrlCreateButton("&Cancel", 20, -1, 75, 25)
    GUICtrlSetState($Btn_OK, 512)
    GUISetState()
    If $timeout Then $Time = TimerInit()
    While 1
        $Msg = GUIGetMsg()
        Local $sUser = GUICtrlRead($subjectnumber)
        Local $ssess = GUICtrlRead($session)
        If ($Time And TimerDiff($Time) >= $timeout) And ($sUser = "" And $ssess = "") Then
            $Status = 2
            ExitLoop
        EndIf
        Select
            Case $Msg = -3
                $Status = 0
                ExitLoop
            Case $Msg = $Btn_OK
                If $bBlank And ($sUser = "" Or $ssess = "") Then
                    $Status = 1
                    ExitLoop
                Else
                    If $sUser <> "" And $ssess <> "" Then
                        $Status = 1
                        ExitLoop
                    Else
                        Select
                            Case $sUser = "" And $ssess = ""
                                If $ShowError = 1 Then MsgBox(16, "Error!", "subjectnumber and session cannot be blank!")
                            Case $ssess = ""
                                If $ShowError = 1 Then MsgBox(16, "Error!", "session cannot be blank!")
                                GUICtrlSetState($session, 256)
                            Case $sUser = ""
                                If $ShowError = 1 Then MsgBox(16, "Error!", "subjectnumber cannot be blank!")
                                GUICtrlSetState($subjectnumber, 256) ; #############################
                        EndSelect
                    EndIf
                EndIf
            Case $Msg = $Btn_Cancel
                $Status = 0
                ExitLoop
            Case $timeout And TimerDiff($Time) >= $timeout; And $timeout
                If $bBlank And ($sUser = "" Or $ssess = "") Then
                    $Status = 2
                    ExitLoop
                Else
                ;$time = TimerInit()
                    Select
                        Case $sUser = "" And $ssess = ""
                            If $timeout Then $Time = TimerInit()
                            If $ShowError = 1 Then MsgBox(16, "Error!", "subjectnumber and session cannot be blank!")
                        Case $ssess = ""
                            If $timeout Then $Time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "session cannot be blank!")
                                GUICtrlSetState($session, 256)
                            EndIf
                        Case $sUser = ""
                            $Time = TimerInit()
                            If $ShowError = 1 Then
                                MsgBox(16, "Error!", "subjectnumber cannot be blank!")
                                GUICtrlSetState($subjectnumber, 256)
                            EndIf
                        ;Case ($Timeout AND TimerDiff($time) >= $timeout) AND ($sUser = "" OR $ssess = "")
                        ;$status = 2
                        ;ExitLoop
                        Case Else
                            If $sUser <> "" And $ssess <> "" Then
                                $Status = 3
                            ;If $Timeout AND TimerDiff($time) >= $timeout Then $Status = 2
                                ExitLoop
                            EndIf
                    EndSelect
                EndIf
        EndSelect
    WEnd
    Local $eMsg = ""
    Switch $Status
        Case 0, 2
            $err = 1;0
            $ext = 1;Cancel/Exit Button Pressed
            $eMsg = "Cancel/Exit Button Pressed"
            If $Status = 2 Then $ext = 2;Timed Out
            If $ext = 2 Then $eMsg = "Timed Out"
        Case Else;1, 3
            $retarr[0] = $sUser
            $retarr[1] = $ssess
            $err = 0;1
            $ext = 0
            If $Status = 3 Then $ext = 1;subjectnumberFields Not Blank, Timeout reached
    EndSwitch
    GUIDelete($gui)
    Opt("GUICoordMode", $iGCM);Reset the GUICoordMode to what it started as.
    If $eMsg Then Return SetError($err, $ext, $eMsg)
    Return $retarr
EndFunc  ;==>_GUICreateLogin

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
penthi

Thank you so much for that Melba!

There is positively steam coming out of my ears by now... I think I did everything correctly with changing the programnames and all that, but it just won't work.

I guess that it is quite possible that eprime doesn't accept input from an outside program (except trough package calls).I am not sure how the "$ret[0]" arrives in the dialogbox? Does it go in there as $ret[0]" that has to be called back into say '12'? Cause E-prime seems to be pretty pesky about the attributes we're trying to change here (subject and session), they are the only two attributes that can't be controlled by the user: i.e. they have to be numeric and can't be set to string or choice like the other options for startupinfo.

For now i think that e-prime (in e-basic) in simply refuses to interact with autoit, somehow.

I am gonna give up for a bit now I guess... if your script can't do it, then there doesn't see to be much chance that i'll figure it out anywhere soon. If every, I'll come and post it.

o/

Share this post


Link to post
Share on other sites
Melba23

penthi,

Send basically mimics the keyboard, so if you can type in, you should be able to Send in!

Try putting WinActivate("E-Run") before you start Sending - just in case there was something else grabbing the limelight and preventing Send from working on the correct window.

If that fails, use the Au3Info tool (you will find in the same folder as Autoit itself) and see what information it gives you about the input windows in your app. If we can get a good ID, we could then try ControlSend to target the actual input area.

If you wish, post a copy of one of the programs (I assume that they are stand-alone executables?) so we can look at it for you. If you would rather not post it publicly, feel free to put it in a PM to me.

Do not give up....at least , not yet! :-)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
penthi

now there's a peptalk!

Let's see... I made a screenshot with the autoitinfothingy.. I am not sure what info is needed exactly? It seems to me that the box is simply called 'E-run'?

I also tried to include an ebs-file of the basic experiment that the program gives as an example-basic-experiment but this filetype is nog permitted.

The thing is that the program itself somehow really defends these two attributes (subject and session). Even if you write an inline in the program ITSELF (no autoit or anything attached) to set these two attributes to a different value, it will ignore this inline.

I'll have to leave for a meeting now and I won't be here tomorrow (here is where I have a computer with E-prime), so i'll check back on monday.

Help would be really appreciated but don't feel obliged or anything!

Regards,

Penthi.

post-48861-1240497640_thumb.gif

Share this post


Link to post
Share on other sites
Melba23

penthi,

Try this main part of the script. I have used ControlSend to pinpoint the input area using the information from the Au3Info tool and deleted all the Notepad lines (they were only there to help me debug).

#include <Array.au3>

;(Number of .ebs2 files -- The line of code below refers to a total of 5 ebs2 files to be run)
Dim $i, $iMax = 5
Dim $FileNameArray[$iMax]

Opt("GUICoordMode", " 2")

$ret = _GUICreateLogin("Enter Credentials", "Enter the subjectnumber and session", -1, -1, -1, -1, -1, 10000)
If @error Then
    MsgBox(0, "Error", "Error Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended)
Else
    MsgBox(0, "Credentials Returned", "subjectnumber: " & $ret[0] & @CRLF & "session:  " & $ret[1])
EndIf

For $x = 0 To UBound($FileNameArray) - 1
    $FileNameArray[$x] = '"' & @WorkingDir & '\' & ($x + 1) & '.ebs2"'
Next

For $i = 1 To $iMax
    
    ; Get a random number to act as an index
    $CurrentNumber = Random(0, UBound($FileNameArray) - 1, 1)
    
    ; Run the selected app
    Run("C:\Program Files\PST\E-Prime 2.0\Program\E-Run.exe /a /m " & $FileNameArray[$CurrentNumber])
    
    ; Wait until the app starts
    WinWait("E-Run")
    WinActivate("E-Run")
    
    ; Here is where you need to send the credentials 
    ControlSend("E-Run", "", "[CLASS:Edit; INSTANCE:1]", $ret[0]); Send the subjectnumber
    Sleep(500)                                                  ; Wait 1/2 sec
    Send ("{ENTER}")                                            ; Enter to close dialog
    
    ; What we do here depends on what the dialog does in your app:
    ; If the dialog closes and another opens, we need to wait and activate it before continuing
    WinWaitClose("E-Run"); <<<<<< Delete if the dialog stays open
    WinWait("E-Run")    ; <<<<<< Delete if the dialog stays open
    WinActivate("E-Run"); <<<<<< Delete if the dialog stays open
    
    ; If the dialog stays open and only the text changes we can assume the same window is open
    ; and the input is merely cleared
    Sleep(500)                                                  ; Wait 1/2 sec
    ControlSend("E-Run", "", "[CLASS:Edit; INSTANCE:1]", $ret[1]); Send the session
    Sleep(500)                                                  ; Wait 1/2 sec
    Send ("{ENTER}")                                            ; Send Enter to close dialog
    
    ; Wait for the app ends
    WinWaitClose("E-Run")
    
    ; Remove this app from the list
    _ArrayDelete($FileNameArray, $CurrentNumber)
    ; Check if any are left - is it still an array basically - and exit if not
    If Not IsArray($FileNameArray) Then Exit
Next

There is one area where you will have to play with this. Depending on what the app dialog does after the first time we press Enter, we either wait for a new dialog - or press on regardless! I think the code is clear enough on which lines are affected, but do ask if you are unsure.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
penthi

You sir, have done the job!

It works!!!!!!! \o/

With a few minor adjustments your script works like a charm. I added in an extra 'send enter' (after the inputboxes the program returns a 'you've given these values, are these ok?'-box) and it really needed some extra sleep before starting the sending part, otherwise the subjectnumber would not arrive, but that's basically all it needed.

You did morph it back to calling the different files in a random order, I suppose there was some rest code still in there that made you do that. Which is fine, one of the other persons that might want to use this script needs exactly that (the person that actually provided the inital 'call ebs files code).

#include <Array.au3>

;(Number of .ebs2 files -- The line of code below refers to a total of 5 ebs2 files to be run)
#include <Array.au3>

;(Number of .ebs2 files -- The line of code below refers to a total of 5 ebs2 files to be run)
Dim $i, $iMax = 5
Dim $FileNameArray[$iMax]

Opt("GUICoordMode", " 2")

$ret = _GUICreateLogin("Enter Credentials", "Enter the subjectnumber and session", -1, -1, -1, -1, -1, 10000)
If @error Then
    MsgBox(0, "Error", "Error Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended)
Else
    MsgBox(0, "Credentials Returned", "subjectnumber: " & $ret[0] & @CRLF & "session:  " & $ret[1])
EndIf

For $x = 0 To UBound($FileNameArray) - 1
    $FileNameArray[$x] = '"' & @WorkingDir & '\' & ($x + 1) & '.ebs2"'
Next

For $i = 1 To $iMax
    
   ; Get a random number to act as an index
    $CurrentNumber = Random(0, UBound($FileNameArray) - 1, 1)
    
   ; Run the selected app
    Run("C:\Program Files\PST\E-Prime 2.0\Program\E-Run.exe /a /m " & $FileNameArray[$CurrentNumber])
    
   ; Wait until the app starts
    WinWait("E-Run")
    WinActivate("E-Run")
       Sleep(1000)  
   ; Here is where you need to send the credentials
    ControlSend("E-Run", "", "[CLASS:Edit; INSTANCE:1]", $ret[0]); Send the subjectnumber
    Sleep(500)                                                 ; Wait 1/2 sec
    Send ("{ENTER}")                                           ; Enter to close dialog

    
   ; If the dialog stays open and only the text changes we can assume the same window is open
   ; and the input is merely cleared
    Sleep(500)                                                 ; Wait 1/2 sec
    ControlSend("E-Run", "", "[CLASS:Edit; INSTANCE:1]", $ret[1]); Send the session
    Sleep(500)                                                 ; Wait 1/2 sec
    Send ("{ENTER}")                                           ; Send Enter to close dialog
     Sleep(500)   
    Send ("{ENTER}")  
   ; Wait for the app ends
    WinWaitClose("E-Run")
    
   ; Remove this app from the list
    _ArrayDelete($FileNameArray, $CurrentNumber)
   ; Check if any are left - is it still an array basically - and exit if not
    If Not IsArray($FileNameArray) Then Exit
Next

If it is ok with you I'll share the total code with the users on the eprime google group. Off course I'll also use it myself and chances are that colleagues will wanna borrow this (and lend it out again)... so... I hope that you'll be happy to hear that there is a good chance that your coding will be used by a fair number of reseachers. I'll add in a proper 'credits due to' in the beginning of the code that will have your shiny name on it.

Share this post


Link to post
Share on other sites
Melba23

penthi,

Some people are never satisfied! ;-)

Here is the "in order" script (you will have to amend the same parts you needed to change last time):

#include <Array.au3>

;(Number of .ebs2 files -- The line of code below refers to a total of 5 ebs2 files to be run)
Dim $i, $iMax = 5

Opt("GUICoordMode", " 2")

$ret = _GUICreateLogin("Enter Credentials", "Enter the subjectnumber and session", -1, -1, -1, -1, -1, 10000)
If @error Then
    MsgBox(0, "Error", "Error Returned: " & $ret & @CRLF & "Error Code: " & @error & @CRLF & "Extended: " & @extended)
Else
    MsgBox(0, "Credentials Returned", "subjectnumber: " & $ret[0] & @CRLF & "session:  " & $ret[1])
EndIf

For $i = 1 To $iMax
    
  ; Run the selected app
    Run("C:\Program Files\PST\E-Prime 2.0\Program\E-Run.exe /a /m " & '"' & @Workingdir & '\' & $i & '.ebs2"'
    
  ; Wait until the app starts
    WinWait("E-Run")
    WinActivate("E-Run")
       Sleep(1000)  
  ; Here is where you need to send the credentials
    ControlSend("E-Run", "", "[CLASS:Edit; INSTANCE:1]", $ret[0]); Send the subjectnumber
    Sleep(500)                                                ; Wait 1/2 sec
    Send ("{ENTER}")                                          ; Enter to close dialog

    
  ; If the dialog stays open and only the text changes we can assume the same window is open
  ; and the input is merely cleared
    Sleep(500)                                                ; Wait 1/2 sec
    ControlSend("E-Run", "", "[CLASS:Edit; INSTANCE:1]", $ret[1]); Send the session
    Sleep(500)                                                ; Wait 1/2 sec
    Send ("{ENTER}")                                          ; Send Enter to close dialog
     Sleep(500)   
    Send ("{ENTER}")  
  ; Wait for the app ends
    WinWaitClose("E-Run")
    
  ; Remove this app from the list
    _ArrayDelete($FileNameArray, $CurrentNumber)
  ; Check if any are left - is it still an array basically - and exit if not
    If Not IsArray($FileNameArray) Then Exit
Next

Glad to have been of help - delighted that it will be useful - thanks for the offer of credit. Have a good weekend.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
penthi

Hahaha.. ooh sorry >.<

It wasn't ment to ask you for an 'in order'script.... I suck at this but I did manage to reform a random order script into an in order script.... your effort is really highly appreciated though!

I DO have one last thing... because I used a 'username & password'loginbox as a basis for the dialoguebox the second input (session, used to be password) is not shown when it is typed in, instead a * is shown.... it's rather minor but do you happen to be ablo to identify in a glance which line is responsible for that?

Have a nice weekend yourself!!

Share this post


Link to post
Share on other sites
Melba23

penthi,

Change the line in the _GUICreateLogin function that currently reads:

Local $session = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21, 32)

to read:

Local $session = GUICtrlCreateInput('', 8, -1, $hWidth - 81, 21)

That removes the $ES_PASSWORD style and shows the input in clear.

Check your PMs please.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
penthi

Check! That's adjusted now, It would have probably taken me ages to find that villain of a " ,32 "

I also checked the pm's and replied (twice now) but no 'sent messages' or anything of the kind show up. I suppose a forumbug there, if not pm me again and I'll take another attempt at replying ^.^

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  

×