Grax Posted May 16, 2008 Posted May 16, 2008 (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 May 16, 2008 by Grax
evilertoaster Posted May 17, 2008 Posted May 17, 2008 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
Grax Posted May 19, 2008 Author Posted May 19, 2008 I figured it out. I had to check for EOF, which would indicate no result was found that meet the SQL search criteria. Andrew
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