Jump to content

How Stop Autoit in background if there is a problem on the Application it Controls


goodcryan
 Share

Recommended Posts

HI,

Currently I have created a script that control our ERP Application which throws data on specific ERP transaction Window from excel.

Now there is an instance that ERP hangs or there is a Error message displayson ERP and myscript still runs and by pass this and my code still continue even the cursor is not on the correct control class.

How to deal with this? I also need to continue transaction if ERP now is ok without any user confirmation.

Thanks in Regards

Here is my Code:

$g_szVersion = "ERP"
If WinExists($g_szVersion) Then Exit ; It's already running
AutoItWinSetTitle($g_szVersion)
 
HotKeySet("!e", "Terminate")    ;shift-alt-e
Func Terminate()
    Exit 0
EndFunc
 
#include <Excel.au3>
$sFilePath1 = @ScriptDir & "\ERP.xls" ;This file should already exist
$oExcel = _ExcelBookOpen($sFilePath1)
_ExcelSheetActivate($oExcel, "ERP")
 
 
 
If @error = 1 Then
    MsgBox(0, "Error!", "Unable to Create the Excel Object")
    Exit
ElseIf @error = 2 Then
    MsgBox(0, "Error!", "File does not exist")
    Exit
EndIf
 
 
$myrow=inputbox("ERP","Enter starting row number for  in ERP.")
$myrow2=inputbox("ERP","Enter last row number for  in ERP.")
$myrow=int($myrow)
$myrow2=int($myrow2)
 
if $myrow=0 then
Exit
EndIf
if $myrow>$myrow2 then
Exit
EndIf
 
while 1
 
$sCellValue = _ExcelReadCell($oExcel, $myrow, 1)
$me = _ExcelReadCell($oExcel, $myrow, 2) ;comp PN
$cpn=$me
 
WinActivate ("Intuitive ERP")
Send($me)
Send("{TAB}")
sleep(500)
 
;SEND Default 4410 warehouse
 
WinActivate ("Intuitive ERP")
Send("4410")
Send("{TAB}")
sleep(500)
 
;SEND FROM
$sCellValue = _ExcelReadCell($oExcel, $myrow, 1)
$from = _ExcelReadCell($oExcel, $myrow, 3) ;from
$cpn=$from
 
 
WinActivate ("Intuitive ERP")
Send($from)
Send("{TAB}")
sleep(500)
 
 
;SEND LOC QTY
$sCellValue = _ExcelReadCell($oExcel, $myrow, 1)
$qty = _ExcelReadCell($oExcel, $myrow, 4) ;qty
$cpn=$qty
 
 
WinActivate ("Intuitive ERP")
Send($qty)
Send("{TAB}")
sleep(500)
 
 
;BY PASS GL DATE
Send("{TAB}")
sleep(500)
 
 
;SEND Default 4410 warehouse
 
WinActivate ("Intuitive ERP")
Send("4410")
Send("{TAB}")
sleep(500)
 
 
;SEND To
$sCellValue = _ExcelReadCell($oExcel, $myrow, 1)
$to = _ExcelReadCell($oExcel, $myrow, 5) ;to
$cpn=$to
 
 
WinActivate ("Intuitive ERP")
Send($to)
Send("{TAB}")
sleep(500)
 
 
;Press Accept
Send("{ENTER}")
sleep(1500)
 
 
while 1    ;waiting for a the entry to save
;$save=$save+1
$check=$me
if not $check=$cpn then
ExitLoop
EndIf
WEnd
 
 
_ExcelWriteCell($oExcel,$sCellValue & "Transacted", $myrow, 1) ;Write to the Cell
if $myrow=$myrow2 then
Exit
EndIf
 
$myrow=$myrow+1
 
 
WEnd
Edited by goodcryan
Link to comment
Share on other sites

Is the error some kind of an error messagebox? if so I would continuously check if it exists with something like

If WinExists("error window title") then winclose("error window title")
Edited by Beege
Link to comment
Share on other sites

All Erp title is generic so you cant check specific title.

The Erp controls doesn't have class name so i just did is to check the timing and do tab and enter event.

And when ERp is idle and the cursor is on a inputbox,my script continue even it is not on the correct line. - another problem

Link to comment
Share on other sites

What do you mean "generic"? And when it appears does it steal focus and become the active window? If so mabey you can do something where you check using WinActive('Intuitive ERP') that your main app is still the active window. If its not the active window any more then the error box must have appeared. Then use:

$Errorbox = WinGetActive()

WinClose($Errorbox)

Edited by Beege
Link to comment
Share on other sites

All Erp title is generic so you cant check specific title.

I'm guessing you mean that the ERP title is the same for all windows including the error. There must be some hidden or visible text you could use with WinWait() as it must have 'Error' somewhere in the window eg:

If WinExists("Intuitive ERP", "error") then winclose("Intuitive ERP", "Error")

[font='Comic Sans MS']Eagles may soar high but weasels dont get sucked into jet engines[/font]

Link to comment
Share on other sites

You could also use the autoit info tool and get the size of the error box, then use wingetpos to check for a window the size of the error box...

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Link to comment
Share on other sites

You can check this:

http://www.imagesocket.com/photos/guest/2333311

I mean All ERP Window Title is all the same. When i use Info Tool it just see the whole instance of form and cannot get the class name of Buttons etch on that specific form so i just did is to do Send Tab/Send Enter for the timing of throwing data...

check my other post

And I think i am so closed with the solution now...I will do all of your suggestions and send an update.

Edited by goodcryan
Link to comment
Share on other sites

I use a program at work where there are no controls, all windows have the same name, etc.

in my loops where an error box could pop up, I do something like this

$search = PixelSearch(465, 213, 845, 273, 0xFF8080)
Do
  $search = PixelSearch(465, 213, 845, 273, 0xFF8080)
  $pos = WinGetPos("[CLASS:Chimenix]")
  If $pos[2] = 422 And $pos[3] = 132 Then;width and height of error box
   Sleep(500)
   Send("{ENTER}")
   ControlSend("AutoItlog", "", 15, "Workflow in use" & " " & @HOUR & ":" & @MIN & @CRLF)
   $reason = "In use"
   norun()
  EndIf
  Sleep(10)
Until $search <> 1

*edit*

WinGetPos("[CLASS:Chimenix]") <-- this is the same name I get for all windows pertaining to this program but since the window sizes are different, I can tell which is which by the size

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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