pintas Posted October 17, 2019 Share Posted October 17, 2019 (edited) Hi. Is there a way to repeat the while loop below every minute, without exiting the script? I've tried placing it inside a function and call that function every minute, but if i do, it doesn't work. Here's the script: expandcollapse popup#include <GUIConstants.au3> Dim $oMyError $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $ado = ObjCreate( "ADODB.Connection" ) ; Create a COM ADODB Object with the Beta version With $ado .ConnectionString =("Provider='OraOLEDB.Oracle';Data Source='ORA2011d';User Id='user';Password='user';") .Open EndWith $adors = ObjCreate( "ADODB.RecordSet" ) ; Create a Record Set to handles SQL Records $adors2 = ObjCreate( "ADODB.RecordSet" ) ; Create a Record Set to handles SQL Records $adors3 = ObjCreate( "ADODB.RecordSet" ) ; Create a Record Set to handles SQL Records With $adors .ActiveConnection = $ado ;.CursorLocation = "adUseClient" ;.LockType = "adLockReadOnly" ; Set ODBC connection read only .Source = "select a.cd_ocr_prc from tpcclr_ddo a where a.cd_ocr_prc in (112,113) and to_char(A.DT_LCT, 'DD/MON/YYYY HH24:MI') = to_char(SYSDATE - 1/24/60, 'DD/MON/YYYY HH24:MI')" .Open EndWith With $adors2 .ActiveConnection = $ado .Source = "select a.cd_grp_maq from tpcclr_ddo a where a.cd_ocr_prc in (112,113) and to_char(A.DT_LCT, 'DD/MON/YYYY HH24:MI') = to_char(SYSDATE - 1/24/60, 'DD/MON/YYYY HH24:MI')" .Open EndWith With $adors3 .ActiveConnection = $ado .Source = "select a.cd_maq from tpcclr_ddo a where a.cd_ocr_prc in (112,113) and to_char(A.DT_LCT, 'DD/MON/YYYY HH24:MI') = to_char(SYSDATE - 1/24/60, 'DD/MON/YYYY HH24:MI')" .Open EndWith ;WHILE LOOP STARTS HERE While not $adors.EOF For $i = 0 To $adors.Fields.Count - 1 $TrimApont1 = StringReplace($adors.Fields( $i ).Value, "112", "QUEBRA MECÂNICA") $TrimApont2 = StringReplace($TrimApont1, "113", "QUEBRA ELÉTRICA") $Maq = $adors2.Fields( $i ).Value & " " & $adors3.Fields( $i ).Value $FullString = $TrimApont2 & " - " & $Maq MsgBox(48, "Quebra de máquina", $FullString) Next $adors.MoveNext $adors2.MoveNext $adors3.MoveNext ; Go to the next record WEnd ; This COM error Handler Func MyErrFunc() $HexNumber=hex($oMyError.number,8) ConsoleWrite("We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfunc Edited October 17, 2019 by pintas Solved. Link to comment Share on other sites More sharing options...
mikell Posted October 17, 2019 Share Posted October 17, 2019 You might put it inside a func, use AdlibRegister, and put an empty While loop at the end of the script to keep it alive pintas 1 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted October 17, 2019 Moderators Share Posted October 17, 2019 @pintas There are a number of ways you could go about it. You could always surround your current While loop in another While loop that runs the inner loop and then sleeps for 60 seconds. A much better approach would be to use the Task Scheduler on your script as you'll have options for what to do in the case of failure. pintas 1 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
pintas Posted October 17, 2019 Author Share Posted October 17, 2019 Thank you guys! The problem was not the while loop. I had to close Oracle connections first. Thank you so much. Solved! 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