I'm trying to use the APAX serial I/O control
(www.turbocontrol.com/AProZilla.htm) in a VB.NET project and I'm having
trouble with its 'data received' events. The data is supplied by APAX
as a variant which appears to VB.NET as a System.Object. I want to
convert this to a System.Array so that I can iterate over its elements.
The VB6 usage is described at
www.turbocontrol.com/TechTips/20020426.htm. If I try something similar
in VB.NET, namely
Private Sub AxApax1_OnRXD(B yVal sender As Object, ByVal e As
AxApax1.IApaxEv ents_OnRXDEvent ) Handles AxApax1.OnRXD
Dim i As Integer
For i = LBound(e.data) To UBound(e.data)
Debug.Writeline (e.data(i))
Next
End Sub
then the IDE underlines each occurrence of e.data and says "Option
Strict On disallows implicit conversion from System.Object to
System.Array". If I turn Option Strict off, everything works fine and
my serial data is printed to the Output window.
I've tried things like
Dim data() As Byte = DirectCast(e.da ta, Byte())
For Each b As Byte In data
Debug.Writeline (b)
Next
and CType instead of DirectCast, but although this compiles OK
execution doesn't seem to get beyond the Dim data() line! No error or
exception is raised. If I put a breakpoint on this line, execution
stops when data is received and I've checked that e.data does indeed
contain the serial data I'm sending, but if I hit F8 to step to the For
Each line, the IDE seems to step out of this event handler and the loop
is not executed. No data is printed to the Output window and execution
breaks again on the Dim data() line when more data is received.
The other weird thing is that if I type '?e.data' in the Command
window, it tells me that e.data *is* already a System.Array:
?e.data
{System.Array}
(&H1): &H41
(&H2): &H2C
(&H3): &H2C
[...]
So why is the IDE complaining? Any idea what's going on, and how I can
get this cast to work? I'm using VS.NET 2003 v7.1.3088 under Win2K
SP4.
Mike.