SkysLastChance

[SOLVED] Why is my code not looping?

5 posts in this topic

#1 ·  Posted (edited)

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

Life's simple. You make choices and you don't look back.

Share this post


Link to post
Share on other sites

#2 ·  Posted (edited)

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

When the msgbox appears and you click ok, you set $sbox to 1, which after the second pass $r will be > $sbox

1 person likes this

 

Spoiler

WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]
Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ]

 

Share this post


Link to post
Share on other sites

Good finding :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

 

1 person likes this

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

  • Similar Content

    • Ascer
      By Ascer
      1. Description.
      Udf working with MSDN System.Collections.ArrayList. Allow you to make fast operations on huge arrays, speed is even x10 better than basic _ArrayAdd.  Not prefered for small arrays < 600 items. 2. Requirements
      .NET Framework 1.1+ System Windows 3. Possibilities.
      ;=============================================================================================================== ; UDF Name: List.au3 ; ; Date: 2018-02-17, 10:52 ; Description: Simple udf to create System Collections as ArrayList and make multiple actions on them. ; ; Function(s): _ListCreate -> Creates a new list ; _ListCapacity -> Gets a list size in bytes ; _ListCount -> Gets items count in list ; _ListIsFixedSize -> Get bool if list if fixed size ; _ListIsReadOnly -> Get bool if list is read only ; _ListIsSynchronized -> Get bool if list is synchronized ; _ListGetItem -> Get item on index ; _ListSetItem -> Set item on index ; ; _ListAdd -> Add item at end of list ; _ListClear -> Remove all list items ; _ListClone -> Duplicate list in new var ; _ListContains -> Get bool if item is in list ; _ListGetHashCode -> Get hash code for list ; _ListGetRange -> Get list with items between indexs ; _ListIndexOf -> Get index of item ; _ListInsert -> Insert a new item on index ; _ListInsertRange -> Insert list into list on index ; _ListLastIndexOf -> Get index last of item ; _ListRemove -> Remove first found item ; _ListRemoveAt -> Remove item in index ; _ListRemoveRange -> Remove items between indexs ; _ListReverse -> Reverse all items in list ; _ListSetRange -> Set new value for items in range ; _ListSort -> Sort items in list (speed of reading) ; _ListToString -> Get list object name ; _ListTrimToSize -> Remove unused space in list ; ; Author(s): Ascer ;=============================================================================================================== 4. Downloads
      List.au3 5. Examples
      SpeedTest _ArrayAdd vs ListAdd SpeedTest ArraySearch vs ListIndexOf Basic usage - crating guild with members  
    • FMS
      By FMS
      Hello,
      I'm trying to read a binary file to an array but couln't get it to work.
      Also I coul not find any help in the forum around this subject whish was helpfull.
      Is there any way it could be done?
      I tried a lot of ways but maybe somebody know's the right way?
      #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <File.au3> #include <Array.au3> #include <AutoItConstants.au3> Local $in=FileOpen("TEST_labels.idx1-ubyte",16) ; 16+0=Read binary Local $data = FileRead($in) Local $FileArray = BinaryToString($data,4) ;~ $FileArray = StringSplit($BinarydData, @CRLF, 1+2) ;~ Local $FileArray = StringRegExp($BinarydData, "[^\r\n]+", 3) FileClose($in) _ArrayDisplay($FileArray,"$FileArray","",32) MsgBox($MB_SYSTEMMODAL, "", "$FileArray = " & $FileArray )  
      TEST_labels.idx1-ubyte
    • ur
      By ur
      I am reading a CSV file which is tab seperated as below.
      Local $aArray = FileReadToArray($file) And now, I am splitting this main array record wise so that Array contains internally another arrow to represent each row.
      For $i = 0 to (UBound($aArray) - 1) ;MsgBox(0,"",$aArray[$i]) $aArray[$i] = StringSplit(StringStripCR($aArray[$i]), Chr(9),2);Chr(9) for tab ;_ArrayDisplay($aArray[$i]) Next Afther that, _ArrayDIsplay is able to see the individual internal arrays.
      _ArrayDisplay($aArray[1]) But If I try to access the individual element of it as below.It is not showing any result.
      MsgBox(0,"",$aArray[1][1]) Any suggestion, below is the sample csv file.
      New Text Document.csv
    • Jibsbrown
      By Jibsbrown
      Need some help understanding why the ConsoleWrite works inside 2nd For loop but not out side. Between Audit Wiki, Help file , Forum searching (lots of code reading), and YouTube ( shout out to TutsTeach), I have not been able to find the reason why. 
      $sIniPath = "installLog.ini" ; - Get section name $iniSctionNames = IniReadSectionNames($sIniPath) ; - Get Keys and Vaules For $a = 1 to UBound($iniSctionNames) - 1 $keys = IniReadSection($sIniPath , $iniSctionNames[$a]) For $b = 1 to UBound($keys) - 1 $oldSysInfo = IniRead($sIniPath , $iniSctionNames[1], $keys[$b][0], "") $PntIPInfo = IniRead($sIniPath , $iniSctionNames[2], $keys[$b][0], "") $NewPCInfor = IniRead($sIniPath , $iniSctionNames[3], $keys[$b][0], "") ;ConsoleWrite($oldSysInfo & @LF) Next ;ConsoleWrite($oldSysInfo & @LF) Next ConsoleWrite($oldSysInfo) My intention is to use the variables later for Listboxes. Any explanation, forum post links or whatever would help. Sorry also very very new to Autoit.
      Also here's the ini file.
      [OldSysInfo] 4=192.168.0.4|DESKTOP-RDIU2SN|R90M05Q8 5=192.168.0.5|SD0123456789101|R9WGP9P 6=192.168.0.6|SD0123456789102|R9WGP9PT 3=192.168.0.3|DESKTOP-3RS4LKL|R9WGP9P 23=192.168.0.23|SD0123456789102|MXL1234P5I [PrinterIp] 50=192.168.0.50 48=192.168.0.48 47=192.168.0.47 [NewSysInfo] newPC = SD0123456789adfs|192.168.0.185|2UA1234FTR Thank you for your time.
    • KING_NK
      By KING_NK
      #RequireAdmin
      Global $x=0
      Global $y=0
      Func Start()
      While 1
      AutoItSetOption('MouseCoordMode',0)
      AutoItSetOption('SendKeyDelay',10)
      WinActivate('XXX')
      MouseClick('Primary',852,62,1,10)
      sleep(2200)
      MouseClick('Primary',880,196,1,10)
      Send('260',0)      -----------------------> $a as 260
      MouseClick('Primary',880,196,1,0)
      sleep(2200)
      MouseClick('Primary',1019,194,1,10)
      Sleep(2200)
      Send('98',0) ------------------------->$b as 98
      sleep(1000)
      Wend
      EndFunc
       
       
      I want to use Different number in every loop in the place of $a and  $b.
      Is it possble?If it possible Kindly help me