Jump to content

[SOLVED] Why is my code not looping?


Recommended Posts

I know this code is not pretty by any means, but it will not loop. I have used this loop several diffrend times. 

When I take out the this if statment it loops forever so I am guessing ti has to do with this.

Any ideas on cleaning up code is appreciated too.

If $r > $sBox Then
   Exit
   Endif
#include <Excel.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>



$sBox = InputBox ("Vital Site", "How Many Times")


Excel ()
Logon ()
Sleep (2000)
Auto ()


Func FormatDate($DATE)
    $SPLIT = StringSplit($DATE," ")
    $MM = StringMid($SPLIT[1],5,2)
    $YYYY = StringLeft($SPLIT[1],4)
    $DD = StringMid($SPLIT[1],7,2)
    Return $MM & "/" & $DD & "/" & $YYYY
EndFunc


Func Terminate()
    Exit
EndFunc

HotKeySet(("{ESC}"),"Terminate")



Func Excel ()

While ProcessExists("EXCEL.EXE")
$ms = MsgBox(5,"","Process error.  You have an Excel sheet open.  You must close it in order to let this program work.  Please close it now.")
    If $ms=2 Then Exit
Sleep(250)
WEnd
   Global $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsx)")

If FileExists($sExcelFile) Then
   Global $oExcel = _Excel_Open ()
   $oExcel = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file.

Else
   $oExcel = _Excel_Open()
   $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist.
   EndIf

EndFunc


Func Logon ()

   $portal = ShellExecute ("C:\Program Files (x86)\MEDITECH\SSDWEB.Universe\SSDWEB.LIVEF.Ring\Client.mtad") ;MediTech
   WinWaitActive ("[CLASS:MagicFS]", "", "MagicFS Dispaly5")
   Sleep (300)
   ControlSend("[CLASS:MagicFS]", "", "", ("{F12}"))
   Sleep (700)
   ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}"))
   Sleep (700)
   ControlSend("[CLASS:MagicFS]", "", "", ("{DOWN}"))
   Sleep (700)
   ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}"))
   Sleep (700)
   ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}"))
   Sleep (700)
   ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}"))

EndFunc

WinWaitActive ("[CLASS:MagicFS]", "", "MagicFS Dispaly6")



Func Auto ()

$r = 1

Local $aArray = _Excel_RangeRead($oExcel, Default, Default,1)

For $i = 1 To UBound($aArray) - 1   ;$i =0 Start from row A
      $sR0  = $aArray[$i][0]    ;status
      $sR1  = $aArray[$i][1]    ;first name
      $sR2  = $aArray[$i][2]    ;Last name
      $sR3  = $aArray[$i][3]    ;Last 4 SSN
      $sR4  = $aArray[$i][4]    ;DOB
      $sR5  = $aArray[$i][5]    ;Email Address
      $sR6  = $aArray[$i][6]    ;Mailling Address
      $sR7  = $aArray[$i][7]    ;City
      $sR8  = $aArray[$i][8]    ;state
      $sR9  = $aArray[$i][9]    ;Zip Code
      $sR10 = $aArray[$i][10]   ;Gender
      $sR11 = $aArray[$i][11]   ;Phone



   ControlSend("[CLASS:MagicFS]", "", "", ("{F8}"))
   Sleep (500)
   ControlSend("[CLASS:MagicFS]", "", "", ("{F8}"))
   Sleep (500)
   ControlSend("[CLASS:MagicFS]", "", "", ("N"))
   ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}"))
   Sleep (3000)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR1 & @CR)
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}"))
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR2 & @CR)
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}"))
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR6& @CR)
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}"))
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR7 & @CR)
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR8 & @CR)
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR9 & @CR)
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR11& @CR)
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR5 & @CR) ;Email7
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR5 & @CR)  ;Email
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "", (FormatDate($sR4) & @CR))
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR10 & @CR)
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR3 & @CR)
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "", ("{F8}"))
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "", ("P"))
   Sleep (200)

   $sBox = MsgBox($MB_OK & $MB_TOPMOST,"Patient Portal","After you have entered the patient push OK")
   Sleep (300)
   ControlSend("[CLASS:MagicFS]", "", "", ("{F8 3}"))
   Sleep (200)
   ControlSend("[CLASS:MagicFS]", "", "", ("{ESC}"))
   Sleep (200)
   ControlSend("[CLASS:MagicFS Modal(3)]", "", "", ("{ENTER}"))




$r = $r + 1

If $r > $sBox Then
   Exit
   Endif


Next


EndFunc
Edited by SkysLastChance

You miss 100% of the shots you don't take. -Wayne Gretzky -Michael Scott

Link to comment
Share on other sites

Forget what I posted before.
The solution can be found in the next post.

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

Good finding :)

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

Made a few minor changes that I thought would help:

#include <Excel.au3>
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>

HotKeySet(("{ESC}"),"Terminate")

Global $iBox, $oExcel, $oWorkbook

VitalSite() ;~ Added Input Function
Excel ()
Logon ()
Sleep (2000)
Auto ()

WinWaitActive ("[CLASS:MagicFS]", "", "MagicFS Dispaly6")

Func FormatDate($DATE)
    $SPLIT = StringSplit($DATE," ")
    $MM = StringMid($SPLIT[1],5,2)
    $YYYY = StringLeft($SPLIT[1],4)
    $DD = StringMid($SPLIT[1],7,2)
    Return $MM & "/" & $DD & "/" & $YYYY
EndFunc

Func Terminate()
    Exit
EndFunc

Func VitalSite()
    Local $iMsg
    While 1
        ;~ Turn input into a number
        $iBox = Number(InputBox ("Vital Site", "How Many Times"))
        ;~ If user enters a string or cancels then get them to try again
        If $iBox = 0 Then
            $iMsg = MsgBox(1,'Vital Site', 'Please enter a valid number')
            If $iMsg = 2 Then Exit
        Else
            ExitLoop
        EndIf
    WEnd
EndFunc

Func Excel()
    While ProcessExists("EXCEL.EXE")
        $ms = MsgBox(5,"","Process error.  You have an Excel sheet open.  You must close it in order to let this program work.  Please close it now.")
            If $ms=2 Then Exit
    ;~ Doesn't require sleep since the script is paused by the MsgBox above
    ;~ Sleep(250)
    WEnd
    ;~ Shouldn't use Global Scope inside functions moved to top of script
    Local $sExcelFile = FileOpenDialog("Choose/Create Excel File", @ScriptDir, "(*.xlsx)")

    If FileExists($sExcelFile) Then
        ;~ Shouldn't use Global Scope inside functions moved to top of script
        $oExcel = _Excel_Open ()
        $oWorkbook = _Excel_BookOpen($oExcel,$sExcelFile) ;this will open the chosen xls file.
    Else
        $oExcel = _Excel_Open()
        $oWorkbook = _Excel_BookNew($oExcel, 2);this is here to create the xls file if it does not exist.
   EndIf
EndFunc

Func Logon ()
   $portal = ShellExecute ("C:\Program Files (x86)\MEDITECH\SSDWEB.Universe\SSDWEB.LIVEF.Ring\Client.mtad") ;MediTech
   WinWaitActive ("[CLASS:MagicFS]", "", "MagicFS Dispaly5")
   Sleep (300)
   ControlSend("[CLASS:MagicFS]", "", "", ("{F12}"))
   Sleep (700)
   ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}"))
   Sleep (700)
   ControlSend("[CLASS:MagicFS]", "", "", ("{DOWN}"))
   Sleep (700)
   ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}"))
   Sleep (700)
   ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}"))
   Sleep (700)
   ControlSend("[CLASS:MagicFS]", "", "", ("{RIGHT}"))
EndFunc

Func Auto ()
    Local $r = 1
    Local $aArray = _Excel_RangeRead($oWorkbook)
    ;~ If $iBox is greater than no. of rows in $aArray then $iBox equals the number of rows in $aArray
    If $iBox > (UBound($aArray) - 1) Then $iBox = UBound($aArray) - 1
    For $i = 1 To UBound($aArray) - 1   ;$i =0 Start from row A
        $sR0  = $aArray[$i][0]    ;status
        $sR1  = $aArray[$i][1]    ;first name
        $sR2  = $aArray[$i][2]    ;Last name
        $sR3  = $aArray[$i][3]    ;Last 4 SSN
        $sR4  = $aArray[$i][4]    ;DOB
        $sR5  = $aArray[$i][5]    ;Email Address
        $sR6  = $aArray[$i][6]    ;Mailling Address
        $sR7  = $aArray[$i][7]    ;City
        $sR8  = $aArray[$i][8]    ;state
        $sR9  = $aArray[$i][9]    ;Zip Code
        $sR10 = $aArray[$i][10]   ;Gender
        $sR11 = $aArray[$i][11]   ;Phone
        ControlSend("[CLASS:MagicFS]", "", "", ("{F8}"))
            Sleep (500)
        ControlSend("[CLASS:MagicFS]", "", "", ("{F8}"))
            Sleep (500)
        ControlSend("[CLASS:MagicFS]", "", "", ("N"))
        ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}"))
            Sleep (3000)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR1 & @CR)
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}"))
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR2 & @CR)
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}"))
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR6& @CR)
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "", ("{TAB}"))
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR7 & @CR)
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR8 & @CR)
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR9 & @CR)
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR11& @CR)
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR5 & @CR) ;Email7
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR5 & @CR)  ;Email
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "", (FormatDate($sR4) & @CR))
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR10 & @CR)
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "Edit1", $sR3 & @CR)
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "", ("{F8}"))
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "", ("P"))
            Sleep (200)
        $hBox = MsgBox($MB_OK & $MB_TOPMOST,"Patient Portal","After you have entered the patient push OK")
        ControlSend("[CLASS:MagicFS]", "", "", ("{F8 3}"))
            Sleep (200)
        ControlSend("[CLASS:MagicFS]", "", "", ("{ESC}"))
            Sleep (200)
        ControlSend("[CLASS:MagicFS Modal(3)]", "", "", ("{ENTER}"))
        $r += 1
        If $r > $iBox Then Exit
    Next
EndFunc

 

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

×
×
  • Create New...