Jump to content

[SOLVED] Repeat While loop?


pintas
 Share

Recommended Posts

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:

#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 by pintas
Solved.
Link to comment
Share on other sites

  • Moderators

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

 

"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

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