Jump to content
SkysLastChance

[SOLVED] Why is my code not looping?

Recommended Posts

SkysLastChance

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
water

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 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
zone97

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

  • Like 1

 

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
water

Good finding :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Subz

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

 

  • Like 1

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

    • Jackized
      By Jackized
      Is there a way to loop back to the beginning and keep the already entered data in the GUI Input boxes? I can GUIDelete and start a new GUI but all the typed data has to be redone. Here is a sample.

       
      #Include <GuiConstants.au3> Dim $msg,$okbutton,$cancelbutton,$objOU,$intAccValue,$strGroup1,$strGroup2 Dim $strFirstName,$strLastName,$strUserName,$strUserName2,$strPassword,$strDescription,$strContainer Dim $Combo,$Duration Do $Form1 = GuiCreate("", 300, 300)          GUISetBkColor(0xA6CAF0)         GuiCtrlCreateLabel("First Name:", 50, 10)         $strFirstName = GuiCtrlCreateInput("", 50, 25, 200, 20)         GUICtrlSetState ( $okbutton, $GUI_FOCUS )         GuiSetState()     $okbutton = GUICtrlCreateButton ("OK",75,240,50,20)     $cancelbutton = GUICtrlCreateButton ("Cancel",175,240,50,20) While 1     $msg = GUIGetMsg()     Select     Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton             Exit     Case $msg = $okbutton             $strFirstName = GUICtrlRead($strFirstName)             ExitLoop     EndSelect Wend $len = StringLen($strFirstName)     If $len > "20" then         MsgBox(0, "ERROR Name to long", $strFirstName & " can't be over 20 characters." & @CRLF & "Total: " & $len)         ;Exit         GUIDelete($Form1)     EndIf Until $len < "20" MsgBox(0, "Done", "")  
    • mrtgtr
      By mrtgtr
      I want to do something , after wait 2 min and again do same thing
      But I do do not want with sleep, it must be timer 
      How I do this ?
    • Skeletor
      By Skeletor
      Hi Virtual People,
      My array works perfectly fine. However, what is the best practice if the line in the array doesn't have the correct amount of columns and if I can add a placeholder?

       
      For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") Next  
    • MrCheese
      By MrCheese
      hi all,
      reviewing the forum, this thread is applicable: 
       
       
      I wanted to know if there is now a better way to do this?
      In essence, I load a tab delimited txt file into an array (works well). I used tab, as some fields in the original csv contains commas.
      However, I needed autoit to manipulate this array, and output it as a csv.
      IF my array contains items with a comma, without double quotes around the field, then how best do I get a csv out of this?
      My current workaround is to filewritefromarray tab delimited, then open it in excel and save as a csv. I will need to check this to see how the address fields behave that contain a comma.
       
      Any thoughts would be appreciated.
       
    • Skeletor
      By Skeletor
      Hi All,

      I would like to know how you would take a FileLineRead and insert it into an array which then inserts it into Excel?
      One thing to know is the files content is broken up, so I only use half of the content within $FileRead1.
      So its imperative that the $value1, $value2, etc variables be used. 
      Code below:
      $FileRead1 = FileReadLine("C:\temp\sample.txt",1) For $count = 1 To _FileCountLines($FileRead1) Step 1 $string = FileReadLine($FileRead1, $count) $input = StringSplit($string, ",", 1) $value1 = $input[1] $value2 = $input[2] $value3 = $input[3] $value4 = $input[4] _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value1, "A1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value2, "B1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value3, "C1") _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, $value4, "D1") Next  
×