Jump to content

Recommended Posts

Posted (edited)

I have the code:

$FuncDate = StringRight($FuncDate,4)
    $oRec.Open("SELECT TOP 1 CallRecord_AlarmNumber,CallRecord_Date FROM CallRecord WHERE DATEPART('YYYY',CallRecord_Date)=" & $FuncDate & " ORDER BY CallRecord_Date DESC", $oADO)
    $LastCall = StringLeft($oRec("CallRecord_Date").Value,4)
    If $FuncDate = $LastCall Then
        $ToReturn = $oRec("CallRecord_AlarmNumber").value + 1
    Else
        $ToReturn = 1
    EndIf

Which I need to do some error trapping on. Right now if $FuncDate is greater than what is found the the database the code crashes, on the third line. I need to check for that error and set a special condition for it. How do I do this?

Thanks in Advance!

Edited by Grax
Posted

Error handling is covered in the help file-

Error handling is implemented in the same way as a normal COM Event, using ObjEvent() and a user defined COM Event Function. The only difference is the usage of the fixed string "AutoIt.Error" as the name of the object.

An example:

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler 

; Performing a deliberate failure here (object does not exist)
$oIE = ObjCreate("InternetExplorer.Application")
$oIE.visible = 1
$oIE.bogus 
if @error then Msgbox(0,"","the previous line got an error.")

Exit 


; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

   SetError(1) ; something to check for when this function returns 
Endfunc
Posted

I figured it out. I had to check for EOF, which would indicate no result was found that meet the SQL search criteria.

Andrew

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...