Re: "Late Binding" error is killing me!

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



<Just_a_fan@xxxxxxxx> schreef in bericht
news:90nq14193b36ik565li60h5qr8gj9uq0hi@xxxxxxxxxx
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]





.



Relevant Pages

  • extra properties exposed in WSDL to client
    ... Public Sub New ... Private pDistributorNumber As Integer ... Private pPricelist As String ... Public Property ArticleNumbers() As Integer ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Binary Search Tree - CompareTo Error
    ... bstLedenLijst contains a collection of Persoon objects, you are attempting to compare Persoon objects to a String object! ... Private Class TreeNode ... Private mLeftNode As TreeNode ... Public Sub New ...
    (microsoft.public.dotnet.languages.vb)
  • MS Project Add-in Command Button Event Problem
    ... builds a string and displays it in a message box. ... Private addInInstance As Object ... Public Sub OnBeginShutdownImplements ... Dim toolBar As Microsoft.Office.Core.CommandBar = Nothing ...
    (microsoft.public.office.developer.com.add_ins)
  • MS Project Add-in Command Button Event Problem
    ... builds a string and displays it in a message box. ... Private addInInstance As Object ... Public Sub OnBeginShutdownImplements ... Dim toolBar As Microsoft.Office.Core.CommandBar = Nothing ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: common dialog w/api instead of COMDLG32.OCX, possible?
    ... As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As ... Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias ... Public Property Get FileNameAs String ...
    (microsoft.public.vb.winapi)