Jump to content

Typing Text from Array, Continue with Steps, then Loop


Recommended Posts

I have a piece of code (below) that reads information into an array, does some steps, and calls the array by typing into a selected text box. However, I want to type element one of the array, do many more steps, and then repeat the code starting with the first control click, but call element two and so on. What's the best way to do this?

#include <file.au3>
#include <array.au3> ; only for _ArrayDisplay()

$sFile = "patlistmrn.txt"

;Read in lines of text into 1D array
Dim $text
If Not _FileReadToArray($sFile, $text) Then
    MsgBox(4096, "Error", " Error reading text file to Array error:" & @error)
    Exit
EndIf
_ArrayDisplay($text, "Debug: $text")

ControlClick("Hill-Rom WatchChild-II", "Archive", "[NAME:cmdArchive]")
Sleep(1000)
ControlClick("frmMessagePopup", "OK", "[NAME:HillRomButton]")
Sleep(1000)
MouseMove(2806, 48, 1)
Sleep(100)
MouseClick($MOUSE_CLICK_LEFT)
MouseMove(2806, 105, 1)
Sleep(100)
MouseClick($MOUSE_CLICK_LEFT)
Sleep(200)
ControlClick("frmArchiveRetrival", "", "[NAME:HillRomTextBox; INSTANCE:2]")

For $vElement In $text
    Send($vElement & @CRLF)
Next

 

Link to comment
Share on other sites

Just place the actions you wish to repeat into a function, basic example (untested):

#include <file.au3>
#include <array.au3> ; only for _ArrayDisplay()

$sFile = "patlistmrn.txt"

;Read in lines of text into 1D array
Dim $aElement
If Not _FileReadToArray($sFile, $aElement) Then
    MsgBox(4096, "Error", " Error reading text file to Array error:" & @error)
    Exit
EndIf
For $i = 0 To UBound($aElement) - 1
    _MyFunc($aElement[$i])
Next
_ArrayDisplay($aElement, "Debug: $aElement")

Func _MyFunc($_vElement)
    ControlClick("Hill-Rom WatchChild-II", "Archive", "[NAME:cmdArchive]")
    Sleep(1000)
    ControlClick("frmMessagePopup", "OK", "[NAME:HillRomButton]")
    Sleep(1000)
    MouseMove(2806, 48, 1)
    Sleep(100)
    MouseClick($MOUSE_CLICK_LEFT)
    MouseMove(2806, 105, 1)
    Sleep(100)
    MouseClick($MOUSE_CLICK_LEFT)
    Sleep(200)
    ControlClick("frmArchiveRetrival", "", "[NAME:HillRomTextBox; INSTANCE:2]")
    Send($_vElement & @CRLF)
EndFunc

 

Edited by Subz
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...