473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Late binding problems?

I want to prevent late binding of this statement:

MyServerConnections(Myindex).client = Value
But when I try with the code below, I get an editor error:
"Expression is a value and therefor cant be the target of an assignment"

CType(MyServerConnections(Myindex), PrivateServerConnectionStruct).Client =
value
What is going on here?

For reference, here is the struct definition:

Private Structure PrivateServerConnectionStruct
Dim client As System.Net.Sockets.TcpClient
Dim Connected_To_Server As Boolean
Dim Connected_User_Name As String
Dim Remote_port_num As Integer
Dim Remote_host_name As String
Dim MessageQueue As Queue
End Structure

Dim MyServerConnections As New ArrayList

Feb 17 '06 #1
3 1383
jvb
I didn't test this to see if it actually works, but it doesn't throw
the build error above...

Call this routine...

Private Sub SetMyClient(ByRef ClientToSet As
System.Net.Sockets.TcpClient, ByVal Value As
System.Net.Sockets.TcpClient)
ClientToSet = Value
End Sub

With this call...

Me.SetMyClient(CType(MyServerConnections(MyIndex),
PrivateServerConnectionStruct).client, < System.Net.Sockets.TcpClient
)


Why did you decide to go with a Structure instead of a class? I don't
believe you would have this problem with a class.

Feb 17 '06 #2
This is what I am doing inside the class. There is probably some other way
to do this better, but I need a threadsafe way to get to
"MyServerConnections". I am using the PublicServerStruct as a "key" to look
up a connection. I thought an array pointer would be easy, but I cant
figure it out. So, below is a class that I am working on.

I will paste the class below:
Option Explicit On
'Option Strict On
Public Class COMMON_ServerConnections

Public Structure PublicServerStruct
Dim Remote_port_num As Integer
Dim Remote_host_name As String
End Structure

Private Structure PrivateServerConnectionStruct
Dim client As System.Net.Sockets.TcpClient
Dim Connected_To_Server As Boolean
Dim Connected_User_Name As String
Dim Remote_port_num As Integer
Dim Remote_host_name As String
Dim MessageQueue As Queue
End Structure

shared MyServerConnections As New ArrayList
#Region " Properties "

Public Property Client(ByVal PublicServerConnection As
PublicServerStruct) As System.Net.Sockets.TcpClient
Get
Dim Myindex As Integer =
ReturnArrayIndexOfClient(PublicServerConnection)
If Not IsNothing(Myindex) Then
Return CType(MyServerConnections(Myindex),
PrivateServerConnectionStruct).client
Else
Return Nothing
End If
End Get
Set(ByVal Value As System.Net.Sockets.TcpClient)
Dim Myindex As Integer =
ReturnArrayIndexOfClient(PublicServerConnection)
If Not IsNothing(Myindex) Then
'Cant figure out how to get around late binding.
MyServerConnections(Myindex).client = Value
End If
End Set
End Property

Public Property Connected_To_Server(ByVal PublicServerConnection As
PublicServerStruct) As Boolean
Get
Dim Myindex As Integer =
ReturnArrayIndexOfClient(PublicServerConnection)
If Not IsNothing(Myindex) Then
Return CType(MyServerConnections(Myindex),
PrivateServerConnectionStruct).Connected_To_Server
Else
Return Nothing
End If
End Get
Set(ByVal Value As Boolean)
Dim Myindex As Integer =
ReturnArrayIndexOfClient(PublicServerConnection)
If Not IsNothing(Myindex) Then
'Cant figure out how to get around late binding.
MyServerConnections(Myindex).Connected_To_Server = Value
End If
End Set
End Property

Public Property Connected_User_Name(ByVal PublicServerConnection As
PublicServerStruct) As String
Get
Dim Myindex As Integer =
ReturnArrayIndexOfClient(PublicServerConnection)
If Not IsNothing(Myindex) Then
Return CType(MyServerConnections(Myindex),
PrivateServerConnectionStruct).Connected_User_Name
Else
Return Nothing
End If
End Get
Set(ByVal Value As String)
Dim Myindex As Integer =
ReturnArrayIndexOfClient(PublicServerConnection)
If Not IsNothing(Myindex) Then
'Cant figure out how to get around late binding.
MyServerConnections(Myindex).Connected_User_Name = Value
End If
End Set
End Property

Public Property MessageQueue(ByVal PublicServerConnection As
PublicServerStruct) As String
Get
Dim Myindex As Integer =
ReturnArrayIndexOfClient(PublicServerConnection)
If Not IsNothing(Myindex) Then
Return CType(MyServerConnections(Myindex),
PrivateServerConnectionStruct).MessageQueue.Dequeu e
Else
Return Nothing
End If
End Get
Set(ByVal Value As String)
Dim Myindex As Integer =
ReturnArrayIndexOfClient(PublicServerConnection)
If Not IsNothing(Myindex) Then
CType(MyServerConnections(Myindex),
PrivateServerConnectionStruct).MessageQueue.Enqueu e(Value)
End If
End Set
End Property

#End Region

Public Function Add(ByVal RemoteHostname As String, ByVal
RemotePortNumber As Integer) As PublicServerStruct

Dim ServerConnection As New PublicServerStruct
ServerConnection.Remote_host_name = RemoteHostname
ServerConnection.Remote_port_num = RemotePortNumber

If ReturnArrayIndexOfClient(ServerConnection) = -1 Then
Dim NewServerConnection As New PrivateServerConnectionStruct
NewServerConnection.Remote_host_name = RemoteHostname
NewServerConnection.Remote_port_num = RemotePortNumber
NewServerConnection.MessageQueue = New Queue

MyServerConnections.Add(NewServerConnection)
End If
End Function

Public Sub Remove(ByVal PublicServerConnection As PublicServerStruct)
Dim Myindex As Integer =
ReturnArrayIndexOfClient(PublicServerConnection)
If Not IsNothing(Myindex) Then
MyServerConnections.Add(Myindex)
End If
End Sub
Public Function ReturnAllConnections() As ArrayList

Dim MyConnections As ArrayList
Dim PrivateConnection As PrivateServerConnectionStruct

For Each PrivateConnection In MyServerConnections
Dim ServerConnection As New PublicServerStruct
ServerConnection.Remote_host_name =
PrivateConnection.Remote_host_name
ServerConnection.Remote_port_num =
PrivateConnection.Remote_port_num
MyConnections.Add(ServerConnection)
Next

Return MyConnections
End Function

Private Function ReturnArrayIndexOfClient(ByVal PublicServerConnection
As PublicServerStruct) As Integer
Dim ServerConnection As New PrivateServerConnectionStruct

Dim MyIndex As Integer = 0
For Each ServerConnection In MyServerConnections
MyIndex += 1
If ServerConnection.Remote_host_name =
PublicServerConnection.Remote_host_name Then
If ServerConnection.Remote_port_num =
PublicServerConnection.Remote_port_num Then
Return MyIndex
End If
End If
Next

'Cant find anythnig, so return ... -1

Return -1
End Function
End Class
Feb 17 '06 #3
Ok, this appears to be working. Its the wierdest thing I have seen yet in
..Net:

It appears that Directly manipulating the MyServerConnections ArrayList
confuses everything. So, creating a "pointer", updating the pointer then
copying back seems to be working. WHAT A PAIN.

Is this a bug? This is not how you would think it should work.

Public Function SetClient(ByVal PublicServerConnection As
PublicServerStruct, ByRef MyClient As System.Net.Sockets.TcpClient)
Dim Myindex As Integer =
ReturnArrayIndexOfClient(PublicServerConnection)

If Not IsNothing(Myindex) Then
Dim LocalPrivateServer As PrivateServerConnectionStruct
LocalPrivateServer = CType(MyServerConnections(Myindex - 1),
PrivateServerConnectionStruct)
LocalPrivateServer.client = MyClient
MyServerConnections(Myindex - 1) = LocalPrivateServer
End If
End Function
"gregory_may" <None> wrote in message
news:e%****************@TK2MSFTNGP10.phx.gbl...
I want to prevent late binding of this statement:

MyServerConnections(Myindex).client = Value
But when I try with the code below, I get an editor error:
"Expression is a value and therefor cant be the target of an assignment"

CType(MyServerConnections(Myindex), PrivateServerConnectionStruct).Client
= value
What is going on here?

For reference, here is the struct definition:

Private Structure PrivateServerConnectionStruct
Dim client As System.Net.Sockets.TcpClient
Dim Connected_To_Server As Boolean
Dim Connected_User_Name As String
Dim Remote_port_num As Integer
Dim Remote_host_name As String
Dim MessageQueue As Queue
End Structure

Dim MyServerConnections As New ArrayList

Feb 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Mike MacSween | last post by:
Had some trouble with Word automation. Sorted it, in the process thought I would try late binding. Some people reccomend it. So this: *********************************************************...
1
by: JD Kronicz | last post by:
Hi .. I have an issue I have been beating my head against the wall on for some time. I am trying to use late binding for MS graph so that my end users don't have to worry about having the right...
9
by: Zlatko Matić | last post by:
I was reading about late binding, but I'm not completely sure what is to be done in order to adjust code to late binding... For example, I'm not sure if this is correct: early binding: Dim ws...
9
by: John Smith | last post by:
Hey, I'm having a difficult time finding some good examples of late binding Outlook in C#. Anyone know of any good sites out there? I've googled and MSDN'ed, but have come up a bit empty. ...
5
by: eBob.com | last post by:
In another thread VJ made me aware of Tag. Fantastic! I've been wanting this capability for a long time. But it seems that I cannot use it with Option Strict On. In an event handler I have ......
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
6
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document...
3
ADezii
by: ADezii | last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile...
4
by: Siv | last post by:
Hi, I have this block of old code: Private Sub txtBoxes_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) _ Handles txtQL12.DragDrop, txtQL11.DragDrop,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.