How to get DataAvailable for Serial Ports created in code

When I create a Serial port (array) in code, how do I get the DataAvailable and Error events?

The Language Reference says this is easy to do, But I can’t see how get the port events?
For example I can create an array of ports thus:

Dim Ser(0) As Serial

Ser(0) = New Serial
Ser(0).Baud etc…
Ser(0).Open
Ser(0).Write “Hello”

But what happens when data arrives?

Use AddHandler.

[code]Dim Ser(0) As Serial

Ser(0) = New Serial()
AddHandler Ser(0).DataAvailable, AddressOf DataAvailable_Handler // or any other valid method name
AddHandler Ser(0).Error, AddressOf MySerError // or any other valid method name
AddHandler Ser(0).LineStateChanged, AddressOf LineStateChanged_Handler // or any other valid method name

Ser(0).Open()
Ser(0).Write(“Hello”)[/code]

[code]Sub DataAvailable_Handler(s As Serial) // Note the parameters

End

Sub MySerError(s As Serial) // Note the parameters

End

Sub LineStateChanged_Handler(s As Serial, changedLines() As Integer) // Note the parameters

End[/code]

[quote=356549:@Eli Ott]Use AddHandler.

[code]Dim Ser(0) As Serial

Ser(0) = New Serial()
AddHandler Ser(0).DataAvailable, AddressOf DataAvailable_Handler // or any other valid method name
AddHandler Ser(0).Error, AddressOf MySerError // or any other valid method name
AddHandler Ser(0).LineStateChanged, AddressOf LineStateChanged_Handler // or any other valid method name

Ser(0).Open()
Ser(0).Write(“Hello”)[/code]

[code]Sub DataAvailable_Handler(s As Serial) // Note the parameters

End

Sub MySerError(s As Serial) // Note the parameters

End

Sub LineStateChanged_Handler(s As Serial, changedLines() As Integer) // Note the parameters

End[/code][/quote]
Don’t forget to add corresponding calls to RemoveHandler when you are done with those Serial controls or they’ll leak.

Brilliant, Many thanks for the speedy reply!