Customers who are porting their VB 6.0 ActiveX application to .NET often ask me, if we forgot the implementation of the Error event. To understand why TX Text Control .NET for Windows Forms does not offer such an event, you have to understand how structured error handling works. This really simple sample shows you how you can use Try Catch in VB.NET to do something similar to the On Error Resume Next functionality.

The GetItem method of the TableBaseCollection gets a particular table from the collection with a specific table identifier. In most cases, you could use a For Each statement to iterate through the tables. But in some cases you need to get one specific table. Anyway, if for some reasons, the table is not longer in the current document, you will get an error message saying that the object reference is not set to an instance of an object. In other words: the table does not exist.

This error message can be handled by yourself using the Try Catch statement:

    TextControl1.Tables.GetItem(11).Cells.GetItem(2, 2).Text = "TableCell"
Catch ex As Exception
    MessageBox.Show("My personalized error message!")
End Try

This is just a purely fictional situation. One last tip for the Try Catch statement: you could add a When clause, so that the error is only trapped, if the When clause is fulfilled.

Catch ex As Exception When myFlag = False