Error handling in VBA code

Visual Basic uses the
Err
object as the standard mechanism for dealing with errors.
When the
FactoryTalk View SE
Client object model encounters an error, it raises an error using this standard Visual Basic mechanism. If you do not provide error handling, VBA or VBA’s runtime error handler will display a runtime error to the end user. This should
always
be avoided because the procedure ends unexpectedly.
The following code is an example of what happens when a subroutine that has no error handling, encounters an error. When the subroutine code attempts to set a variable to a nonexistent item in the collection, the error is detected by VBA. This results in a default runtime error dialog box. Actions from this dialog box can stop the subroutine and reset the VBA project. This should always be avoided.
Sub ExampleNoErrorHandling() Dim oDisplay As DisplayClient.Display ' Set the display object to a display that is not loaded. Set oDisplay = Application.LoadedDisplays("Unknown Display") ' The code will stop running on the line above, and will produce a run-time error dialog in FactoryTalk View Studio, ' or will log the error condition in the FactoryTalk View SE Client. ' The next line will not be run. oDisplay.SetFocus End Sub
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal