"Late Binding" error is killing me!

  • Thread starter Thread starter Just_a_fan
  • Start date Start date
J

Just_a_fan

I am getting data from a device via UDP packets and they arrive thus:

wsInverter.GetData(objData) ' Object required here.

I then need to convert each of the returned data of 38 bytes in this
packet to their hex values. Decimal would be OK, too, but I can't get
to them at all!

When I do this simple command, I get an error about late binding being
no good with Strict On:

i = strData(j) ' Simplified version to reduce options

I tried everything I can think of to get to the data. There has to be a
way to get to the bytes. The AxMSWinsockLib.AxWinsock wants an object.

Any advice appreciated. I would prefer to leave strict on. Yeah, I
know, anal retentive!

This is probably a good time to get rid of AxMSWinsock, left over from
VB6, which was the original version of this program. I don't mind that
but it will take a bunch of changes that I will also have to learn
about.

Mike
 
I am getting data from a device via UDP packets and they arrive
thus:

wsInverter.GetData(objData) ' Object required here.

I then need to convert each of the returned data of 38 bytes in this
packet to their hex values. Decimal would be OK, too, but I can't
get to them at all!

When I do this simple command, I get an error about late binding
being no good with Strict On:

i = strData(j) ' Simplified version to reduce options

After having longer discussions about a similar issue, I ask you to
provide an example of the source and destination value(s) and their data
types. Thanks.

Example (of an example):
Source: byte array, content=243 123 45 98 12
Destination: a string containing hex representation of the values,
seperated by blanks: "F3 7B 2D 98 0C"


In general in advance:
- The hexadecimal or decimal representation of values is _always_ a
string.
- AnyByteValue.ToString("X2") returns the hex representation of a byte
- A Stringbuilder object helps creating a string (quickly).


Armin
 
I am getting data from a device via UDP packets and they arrive thus:

wsInverter.GetData(objData) ' Object required here.

I then need to convert each of the returned data of 38 bytes in this
packet to their hex values. Decimal would be OK, too, but I can't get
to them at all!

When I do this simple command, I get an error about late binding being
no good with Strict On:

i = strData(j) ' Simplified version to reduce options

I tried everything I can think of to get to the data. There has to be a
way to get to the bytes. The AxMSWinsockLib.AxWinsock wants an object.

Any advice appreciated. I would prefer to leave strict on. Yeah, I
know, anal retentive!

This is probably a good time to get rid of AxMSWinsock, left over from
VB6, which was the original version of this program. I don't mind that
but it will take a bunch of changes that I will also have to learn
about.

Mike

Hello Mike ,

This might help you with the conversion of the Code , i wrote once tese 2
generic classes for a project of mine



----- UDP SENDER -----

Imports System.Net
Imports System.Net.Sockets
Public Class Broadcaster
#Region "Delegates"
Delegate Sub MessageSuccess()
Delegate Sub MessageFailure()
#End Region
#Region "Private Fields"
Private _NetIPAddress As String
Private _Port As Int16
Private _BroadcastMessage As String
Private myClient As New System.Net.Sockets.UdpClient
Private _Info As Byte()
'Points to MessageSuccess()
Public Event MessageSent As MessageSuccess
'Points to MessageFailure
Public Event MessageFailed As MessageFailure
#End Region
#Region "Properties"
Public Property NetIPAddress() As String
Get
Return _NetIPAddress
End Get
Set(ByVal Value As String)
_NetIPAddress = Value
End Set
End Property
Public Property Port() As Int16
Get
Return _Port
End Get
Set(ByVal Value As Int16)
_Port = Value
End Set
End Property
Public Property BroadcastMessage() As String
Get
Return _BroadcastMessage
End Get
Set(ByVal Value As String)
_BroadcastMessage = Value
End Set
End Property
#End Region
#Region "Methods"
'If this constructor is used, all you need to do is call SendMessage
Public Sub New(ByVal IP_Address As String, ByVal PortNumber As Int16,
ByVal Msg As String)
Me.NetIPAddress = IP_Address
Me.Port = PortNumber
Me.BroadcastMessage = Msg
End Sub
'If this constructor is used, make sure you set the BroadcastMessage
Public Sub New(ByVal IP_Address As String, ByVal PortNumber As Int16)
Me.NetIPAddress = IP_Address
Me.Port = PortNumber
End Sub
Public Sub SendMessage()
_Info = System.Text.Encoding.UTF8.GetBytes(Me.BroadcastMessage)
Dim EndPoint As New IPEndPoint(IPAddress.Parse(Me.NetIPAddress),
Me.Port)
Try
myClient.Send(Me._Info, Me._Info.Length, EndPoint)
RaiseEvent MessageSent()
Catch ex As System.Net.Sockets.SocketException
RaiseEvent MessageFailed()
End Try
End Sub
#End Region
End Class

--- UDP RECEIVER ---

Option Explicit On
Option Strict On
Imports System
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.Threading
Public Class ClsReceiver
Private UDP_Client As New UdpClient
Private UDP_Listener_Port As Integer
Private thdUdp As Thread
Private UDP_Listener As UdpClient
Private blnListen As Boolean = False
Public Event DataArrival(ByVal Data As String)
Public Event Sock_Error(ByVal Description As String)
Public Function UDP_Listen(ByVal Port As Integer) As Boolean
Try
blnListen = True
UDP_Listener_Port = Port
UDP_Listener = New UdpClient(Port)
thdUdp = New Thread(AddressOf GetUDPData)
thdUdp.Name = "thdUdp"
thdUdp.Start()
Catch e As Exception
RaiseEvent Sock_Error(e.ToString)
End Try
End Function
Private Sub GetUDPData()
Dim DData As Byte()
Do While blnListen
Try
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
DData = UDP_Listener.Receive(RemoteIpEndPoint)
If DData.Length > 0 Then
RaiseEvent
DataArrival(System.Text.Encoding.UTF8.GetString(DData))
End If
Thread.Sleep(0)
Catch e As Exception
RaiseEvent Sock_Error(e.ToString)
End Try
Loop
DData = Nothing
End Sub
Public Sub Close()
' Close the listener and abort the thread
blnListen = False
UDP_Listener.Close()
thdUdp.Abort()
End Sub
End Class


i hope they are for some use for you :-)

HTH

Michel Posseth [MCP]
 
Back
Top