Return Codes
If the ExceptionOnError property is set to False, the CWIMAQ, CWMV, CWIMAQVision, and NIOCR control methods return a status code to indicate whether an operation completed successfully. If the return value is something other than zero, it indicates a warning or error. A positive return value indicates a warning, signifying that a problem occurred in the operation, but that you should be able to continue with the application. A negative value indicates an error—a critical problem that has occurred in the operation—and that all other functions or methods dependent on the failed operation also will fail.
To retrieve the return code from a method call, assign the value of the function or method to a long integer variable and check the value of the variable after calling the function or method. For example, the following code checks the return code of the CWIMAQ control Start method.
lerr = CWIMAQ1.Start
If lerr <> 0 Then MsgBox "Error at IMAQ Start: " + CStr(lerr)
In Visual Basic, you can use the MsgBox popup window to display error information. Normally, you can write one error handler for the application instead of duplicating it for every call to a function or method. For example, the following code creates a LogError subroutine to use with the Start method and later functions or methods.
Private Sub LogError(code As Long)
If code <> 0 Then
MsgBox "IMAQ Error: " + CStr(code)
End If
End Sub
To use the LogError subroutine, call LogError before every function or method call. The return code is passed to LogError and processed.
LogError CWIMAQ1.Start