DSIS Posted June 22, 2011 Share Posted June 22, 2011 The following script works most of the time. I engage the compiled version via the task scheduler in Windows. Once in awhile it starts but does not finish. I have no idea why but would like to find out if it is possible. I am not familiar with @error or SetError. I have read the help on both and perused this forum but it is all Greek to me. Could someone point me in the right direction. Thanks. expandcollapse popup#include <Date.au3> #include <INet.au3> #include <WinWaitActive.au3> Dim $STime Dim $ETime Dim $FName Dim $DoCount $FName = "C:\Documents and Settings\Administrator.Stamp\My Documents\MRPLog2" $STime = _DateTimeFormat(_NowCalc(),1) & " " & _DateTimeFormat(_NowCalc(),5) FileOpen($FName,1) FileWrite($FName,@CRLF) FileWrite($FName, "Start MRP Check " & $STime) $DoCount = 0 Do If WinExists("Question") Then ;Does this window exist? WinActivate("Question") ;True: Activate it EndIf $DoCount = $DoCount + 1 Until WinExists("Question") or $DoCount > 1000 ;Loop until the Window exists or loop count > 1,000 FileOpen($FName,1) FileWrite($FName,@CRLF) FileWrite($FName,"Loop count = " & $DoCount) If $DoCount <= 1000 Then ;If Question Window is found proceed _WinWaitActive("Question") send("{TAB}{ENTER}") _WinWaitActive("Information") send("{ENTER}") sleep(1000) Send("!{F4}") _WinWaitActive("Vantage") send("{TAB}{ENTER}") EndIf $ETime = _DateTimeFormat(_NowCalc(),1) & " " & _DateTimeFormat(_NowCalc(),5) FileOpen($FName,1) FileWrite($FName,@CRLF) FileWrite($FName, "End MRP Check Time and Count " & $ETime & " " & $DoCount) ;Begin Send email to MJD ;Setting variables for email function $s_SmtpServer = "192.168.0.12" $s_FromName = "MHoneywell" $s_FromAddress = "MHoneywell" $s_ToAddress = "MikeDunn@dbqstamp.com" $s_Subject = "MRP Check" Dim $as_Body[3] $as_Body[0] = "MRP Check Started " & $STime & @CRLF $as_Body[1] = "MRP Check Finished " & $ETime & @CRLF $as_Body[2] = "Loop Count = " & $DoCount & @CRLF $Respone = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body) $err = @error Link to comment Share on other sites More sharing options...
enaiman Posted June 22, 2011 Share Posted June 22, 2011 Starting and not finishing can be related to: infinite loop Do/Until (not your case because your loop seem to be working OK) or WInWaitActive whan the window you are waiting for does not become active. By the way - what version of AutoIt are you using? I see "WinWaitActive.au3" and _WinWaitActive ... you better then upgrade to the latest version of AutoIt because WinWaitActive is natively supported there. Get latest AutoIt, change _WinWaitActive to the correct one and try again. What you can do to debug the code is: put the script to write to a log file then check the log. This is your modified code - whenever your application hangs, check the log and see where is the problem. Once you find that ... well, you'll have to think of a way to prevent it. expandcollapse popup#include <Date.au3> #include <INet.au3> #include <WinWaitActive.au3> Dim $STime Dim $ETime Dim $FName Dim $DoCount $FName = "C:\Documents and Settings\Administrator.Stamp\My Documents\MRPLog2" $STime = _DateTimeFormat(_NowCalc(),1) & " " & _DateTimeFormat(_NowCalc(),5) FileOpen($FName,1) FileWrite($FName,@CRLF) FileWrite($FName, "Start MRP Check " & $STime) Global $myLog = "C:\myAppLog.txt" FileClose(FileOpen($myLog,2)) $DoCount = 0 Do If WinExists("Question") Then ;Does this window exist? WinActivate("Question") ;True: Activate it FileWriteLine($myLog, "Do/Until Loop: Activated Question Window") EndIf $DoCount = $DoCount + 1 Until WinExists("Question") or $DoCount > 1000 ;Loop until the Window exists or loop count > 1,000 FileWriteLine($myLog, "Do/Until Loop: Exit because counter > 1000 "&$DoCount) FileOpen($FName,1) FileWrite($FName,@CRLF) FileWrite($FName,"Loop count = " & $DoCount) If $DoCount <= 1000 Then ;If Question Window is found proceed FileWriteLine($myLog, "Waiting for Question to be active.") _WinWaitActive("Question") send("{TAB}{ENTER}") FileWriteLine($myLog, "Sent TAB,ENTER to Question") FileWriteLine($myLog, "Waiting for Information to be active.") _WinWaitActive("Information") send("{ENTER}") sleep(1000) Send("!{F4}") FileWriteLine($myLog, "Sent !F4 to Information") FileWriteLine($myLog, "Waiting for Vantage to be active.") _WinWaitActive("Vantage") send("{TAB}{ENTER}") FileWriteLine($myLog, "Sent TAB,ENTER to Vantage") EndIf FileWriteLine($myLog, "All done - sending email.") $ETime = _DateTimeFormat(_NowCalc(),1) & " " & _DateTimeFormat(_NowCalc(),5) FileOpen($FName,1) FileWrite($FName,@CRLF) FileWrite($FName, "End MRP Check Time and Count " & $ETime & " " & $DoCount) ;Begin Send email to MJD ;Setting variables for email function $s_SmtpServer = "192.168.0.12" $s_FromName = "MHoneywell" $s_FromAddress = "MHoneywell" $s_ToAddress = "MikeDunn@dbqstamp.com" $s_Subject = "MRP Check" Dim $as_Body[3] $as_Body[0] = "MRP Check Started " & $STime & @CRLF $as_Body[1] = "MRP Check Finished " & $ETime & @CRLF $as_Body[2] = "Loop Count = " & $DoCount & @CRLF $Respone = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body) $err = @error SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
DSIS Posted June 23, 2011 Author Share Posted June 23, 2011 enaiman - Thanks for the help. Please further explain the WinWaitActive.au3 vs _WinWaitActive comment. Not sure I understand. I believe I am using version 3.2.10. What is the best method for download? Somewhere in the Downloads tab? Where would I go here to get the latest and greatest. Thanks. Link to comment Share on other sites More sharing options...
enaiman Posted June 23, 2011 Share Posted June 23, 2011 lol have you tried the download page? http://www.autoitscript.com/site/autoit/downloads/I am not 100% sure that _WinWaitActive has not been changed since your udf was created. However, downloading the latest is entirely up to you.You can still use the solution I gave you WITH your current AutoIt version (changing back the includes and WinWaitActive to _WinWaitActive). Latest AutoIt version is 3.3.6.1. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now