Jump to content

Function with Array not Behaving like expected


Recommended Posts

I have a fairly large script that does numerous things. However, in the very beginning, a function prints out the line from an array. However, when looping the function, it just prints the same line. When I use only the beginning part of the script and loop that, everything works as expected. I suspect that I'm not using the function correctly, as this if my first time experimenting with one. Any help is appreciated!

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


$sFile = "patlistmrn.txt"
Global $currentNameString
;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("NaviCare WatchChild", "Archive", "[NAME:cmdArchive]") ;Open Archive
    Sleep(1000)
    ControlClick("frmMessagePopup", "OK", "[NAME:HillRomButton]") ;Accept terms of warning
    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]", "Left", 2) ;Select the text in the textbox so that it can be replace
    Send($_vElement & @CRLF) ;Paste contents of array
    Sleep(500)
    ControlClick("frmArchiveRetrival", "Search", "[NAME:HillRomButton; INSTANCE:1]") ;Search MRN string
    Sleep(1000)
    ControlClick("frmMessagePopup", "OK", "[NAME:HillRomButton; INSTANCE:1]") ;If any warning appears, ignore it and bypass
    $bluesearch = PixelSearch(2235, 165, 2236, 166, 0x316AC5, 10)




    If Not @error Then
        MsgBox(4096, "Yeet", "It's right bud") ;If blue shows up at specific point, meaning a record is there
    Else
        MsgBox(4096, "uh oh", "you made a boo boo") ;Else, no record is there
     EndIf




    MouseClick($MOUSE_CLICK_LEFT, 2235, 165, 2)
    Sleep(1000)
    MouseClick($MOUSE_CLICK_LEFT, 2483, 180, 1)
    Sleep(100)


    Dim $lastmouselocation
    Local $keepgoing
    $keepgoing = 1


    Do
        $lastmouselocation = MouseGetPos() ;Save the mouse position as a variable
        $aCoord = PixelSearch($lastmouselocation[0], $lastmouselocation[1], $lastmouselocation[0] + 15, $lastmouselocation[1] + 3, 0x3399FF, 10) ;Search the mouses area for a shade of blue, meaning a record is availible


        If Not @error Then
            ControlClick("frmArchiveRetrival", "", "[NAME:HillRomTextBox; INSTANCE:2]", "Left", 2) ;Double click on the textbox where the MRN is placed
            Sleep(100)
            Send("^c") ;Copy the contents of the textbox (it should be a MRN number, it is referenced later
            Sleep(3000)
            MouseClick($MOUSE_CLICK_LEFT, 2028, 810, 1) ;Click the retrieve button
            Sleep(100)
            ControlClick("frmConfirmationPopup", "OK", "[NAME:HillRomButton; INSTANCE:2]") ;Confirm if a warning appears
            Sleep(5000)
            ControlClick("NaviCare WatchChild", "Archive", "[NAME:cmdArchive]") ;Return to Archive screen
            Sleep(1000)
            ControlClick("frmMessagePopup", "OK", "[NAME:HillRomButton]") ;Acknowledge Warning if one appears
            Sleep(1000)
            MouseMove(2806, 48, 1) ;Move to dropdown box
            Sleep(100)
            MouseClick($MOUSE_CLICK_LEFT) ;Click dropdown box arrow
            MouseMove(2806, 105, 1)
            Sleep(100)
            MouseClick($MOUSE_CLICK_LEFT) ;Change search to MRN
            Sleep(200)
            ControlClick("frmArchiveRetrival", "", "[NAME:HillRomTextBox; INSTANCE:2]", "Left", 2) ;Double click on text field
            Send("^v") ;Paste existing MRN number you copied earlier
            Sleep(500)
            ControlClick("frmArchiveRetrival", "Search", "[NAME:HillRomButton; INSTANCE:1]") ;Click on search
            Sleep(1000)
            $bluesearch = PixelSearch(2235, 165, 2236, 166, 0x316AC5, 10) ;Check to see if a record appeared



            If Not @error Then
                MsgBox(4096, "Yeet", "It's right bud")

            Else
                MsgBox(4096, "All Done", "You've pulled all records for this patient")
                ControlClick("frmMessagePopup", "OK", "[NAME:HillRomButton; INSTANCE:1]") ;Click on search
                ExitLoop

             EndIf


            MouseClick($MOUSE_CLICK_LEFT, 2235, 165, 2)
            Sleep(1000)
            MouseClick($MOUSE_CLICK_LEFT, $lastmouselocation[0], $lastmouselocation[1], 1)
            Sleep(100)
            $keepgoing = 0


        Else
            $keepgoing = 1
         EndIf

Until $keepgoing = 1




    MsgBox(4096, "Next Steps", "Begin to print off strips")
    MouseClick($MOUSE_CLICK_LEFT, 1967, 1043)


Dim $outbeds
$outbeds = 1
Do
    MouseClickDrag($MOUSE_CLICK_LEFT, 3828, 89, 3828, 916)
    Sleep(200)
    $OutBedSearch = PixelSearch(1940, 100, 3810, 940, 0xFF8000, 10)


    If Not @error Then
        MouseClick($MOUSE_CLICK_LEFT, $OutBedSearch[0], $OutBedSearch[1])
        Sleep(2000)
        MouseClick($MOUSE_CLICK_LEFT, 2156, 1045)
        Sleep(2000)
        MouseClick($MOUSE_CLICK_LEFT, 1953, 922)
        Sleep(2000)
        MouseClick($MOUSE_CLICK_LEFT, 1953, 922)
        Sleep(2000)
        MouseMove(2125, 670, 0)
        MouseDown($MOUSE_CLICK_LEFT)
        MouseMove(3800, 670, 8)
        Sleep(1000)



        Dim $i
        $i = 0

        Do
            $aCoord = PixelSearch(2025, 70, 3775, 900, 0xFFFF00, 10)     ;search for pure yellow


            If Not @error Then
                $i = 0
                $x = random(3777, 3780) ;Randomly move the mouse to ensure the strip is being selected
                $y = random(550, 555)
                MouseMove($x, $y)

            Else
                $aCoord = PixelSearch(2025, 70, 3775, 900, 0xF0F069, 10)     ;search for a faded yellow if pure yellow does not exist


                If Not @error Then
                    $i = 0
                    $x = random(3777, 3780)     ;Randomly move the mouse to ensure the strip is being selected
                    $y = random(550, 555)
                    MouseMove($x, $y)

                Else
                    $x = random(3777, 3780)     ;Randomly move the mouse to ensure the strip is being selected
                    $y = random(550, 555)
                    MouseMove($x, $y)
                    Sleep(100)
                    MouseUp("Left")
                    ;;MsgBox(4096, "Color is gone", "Color is gone")
                    ExitLoop
                EndIf

            EndIf
         Until $i = 1


      Sleep(100)
         MouseClick($MOUSE_CLICK_LEFT, 2125, 926) ;Begin printing Process
        Sleep(500)
        ControlClick("Hill-Rom WatchChild-II", "Start", "[NAME:HillRomButton; INSTANCE: 2]")     ;Begin printing Process
        Sleep(700)
        MouseClick($MOUSE_CLICK_LEFT, 2880, 630)
        Sleep(5000)
        ControlClick("Print", "&Print", "[CLASS:Button; INSTANCE:13]")     ;Begin printing Process
        Sleep(3000)
        Send("^v")     ;Paste existing search
        Send("{Enter}")
        Sleep(10000)
        MouseClick($MOUSE_CLICK_LEFT, 1967, 1043)
        Sleep(1000)
        MouseClickDrag($MOUSE_CLICK_LEFT, 3828, 89, 3828, 916)
        Sleep(1000)
        $OutBedSearch = PixelSearch(1940, 100, 3810, 940, 0xFF8000, 10)

        If Not @error Then
            MouseClick($MOUSE_CLICK_LEFT, $OutBedSearch[0], $OutBedSearch[1])
            Sleep(500)
            MouseClick($MOUSE_CLICK_LEFT, 2421, 995)
            Sleep(500)
            MouseClick($MOUSE_CLICK_LEFT, 2070, 410)
        Else
        EndIf
     Else
        $outbeds = 0

    EndIf

Until $outbeds = 0



EndFunc

 

Link to comment
Share on other sites

This part is your problem in your script.

Dim $i
        $i = 0

When you use Dim in a function, it will redeclare your global variable $i, so you're resetting the loop counter every time you run the function. If you want to have a variable with the same name in the function, use Local instead of Dim.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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