I want to prevent late binding of this statement:
MyServerConnect ions(Myindex).c lient = 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(MyServerC onnections(Myin dex), PrivateServerCo nnectionStruct) .Client =
value
What is going on here?
For reference, here is the struct definition:
Private Structure PrivateServerCo nnectionStruct
Dim client As System.Net.Sock ets.TcpClient
Dim Connected_To_Se rver As Boolean
Dim Connected_User_ Name As String
Dim Remote_port_num As Integer
Dim Remote_host_nam e As String
Dim MessageQueue As Queue
End Structure
Dim MyServerConnect ions As New ArrayList 3 1400
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(ByR ef ClientToSet As
System.Net.Sock ets.TcpClient, ByVal Value As
System.Net.Sock ets.TcpClient)
ClientToSet = Value
End Sub
With this call...
Me.SetMyClient( CType(MyServerC onnections(MyIn dex),
PrivateServerCo nnectionStruct) .client, < System.Net.Sock ets.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.
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
"MyServerConnec tions". I am using the PublicServerStr uct 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_ServerCo nnections
Public Structure PublicServerStr uct
Dim Remote_port_num As Integer
Dim Remote_host_nam e As String
End Structure
Private Structure PrivateServerCo nnectionStruct
Dim client As System.Net.Sock ets.TcpClient
Dim Connected_To_Se rver As Boolean
Dim Connected_User_ Name As String
Dim Remote_port_num As Integer
Dim Remote_host_nam e As String
Dim MessageQueue As Queue
End Structure
shared MyServerConnect ions As New ArrayList
#Region " Properties "
Public Property Client(ByVal PublicServerCon nection As
PublicServerStr uct) As System.Net.Sock ets.TcpClient
Get
Dim Myindex As Integer =
ReturnArrayInde xOfClient(Publi cServerConnecti on)
If Not IsNothing(Myind ex) Then
Return CType(MyServerC onnections(Myin dex),
PrivateServerCo nnectionStruct) .client
Else
Return Nothing
End If
End Get
Set(ByVal Value As System.Net.Sock ets.TcpClient)
Dim Myindex As Integer =
ReturnArrayInde xOfClient(Publi cServerConnecti on)
If Not IsNothing(Myind ex) Then
'Cant figure out how to get around late binding.
MyServerConnect ions(Myindex).c lient = Value
End If
End Set
End Property
Public Property Connected_To_Se rver(ByVal PublicServerCon nection As
PublicServerStr uct) As Boolean
Get
Dim Myindex As Integer =
ReturnArrayInde xOfClient(Publi cServerConnecti on)
If Not IsNothing(Myind ex) Then
Return CType(MyServerC onnections(Myin dex),
PrivateServerCo nnectionStruct) .Connected_To_S erver
Else
Return Nothing
End If
End Get
Set(ByVal Value As Boolean)
Dim Myindex As Integer =
ReturnArrayInde xOfClient(Publi cServerConnecti on)
If Not IsNothing(Myind ex) Then
'Cant figure out how to get around late binding.
MyServerConnect ions(Myindex).C onnected_To_Ser ver = Value
End If
End Set
End Property
Public Property Connected_User_ Name(ByVal PublicServerCon nection As
PublicServerStr uct) As String
Get
Dim Myindex As Integer =
ReturnArrayInde xOfClient(Publi cServerConnecti on)
If Not IsNothing(Myind ex) Then
Return CType(MyServerC onnections(Myin dex),
PrivateServerCo nnectionStruct) .Connected_User _Name
Else
Return Nothing
End If
End Get
Set(ByVal Value As String)
Dim Myindex As Integer =
ReturnArrayInde xOfClient(Publi cServerConnecti on)
If Not IsNothing(Myind ex) Then
'Cant figure out how to get around late binding.
MyServerConnect ions(Myindex).C onnected_User_N ame = Value
End If
End Set
End Property
Public Property MessageQueue(By Val PublicServerCon nection As
PublicServerStr uct) As String
Get
Dim Myindex As Integer =
ReturnArrayInde xOfClient(Publi cServerConnecti on)
If Not IsNothing(Myind ex) Then
Return CType(MyServerC onnections(Myin dex),
PrivateServerCo nnectionStruct) .MessageQueue.D equeue
Else
Return Nothing
End If
End Get
Set(ByVal Value As String)
Dim Myindex As Integer =
ReturnArrayInde xOfClient(Publi cServerConnecti on)
If Not IsNothing(Myind ex) Then
CType(MyServerC onnections(Myin dex),
PrivateServerCo nnectionStruct) .MessageQueue.E nqueue(Value)
End If
End Set
End Property
#End Region
Public Function Add(ByVal RemoteHostname As String, ByVal
RemotePortNumbe r As Integer) As PublicServerStr uct
Dim ServerConnectio n As New PublicServerStr uct
ServerConnectio n.Remote_host_n ame = RemoteHostname
ServerConnectio n.Remote_port_n um = RemotePortNumbe r
If ReturnArrayInde xOfClient(Serve rConnection) = -1 Then
Dim NewServerConnec tion As New PrivateServerCo nnectionStruct
NewServerConnec tion.Remote_hos t_name = RemoteHostname
NewServerConnec tion.Remote_por t_num = RemotePortNumbe r
NewServerConnec tion.MessageQue ue = New Queue
MyServerConnect ions.Add(NewSer verConnection)
End If
End Function
Public Sub Remove(ByVal PublicServerCon nection As PublicServerStr uct)
Dim Myindex As Integer =
ReturnArrayInde xOfClient(Publi cServerConnecti on)
If Not IsNothing(Myind ex) Then
MyServerConnect ions.Add(Myinde x)
End If
End Sub
Public Function ReturnAllConnec tions() As ArrayList
Dim MyConnections As ArrayList
Dim PrivateConnecti on As PrivateServerCo nnectionStruct
For Each PrivateConnecti on In MyServerConnect ions
Dim ServerConnectio n As New PublicServerStr uct
ServerConnectio n.Remote_host_n ame =
PrivateConnecti on.Remote_host_ name
ServerConnectio n.Remote_port_n um =
PrivateConnecti on.Remote_port_ num
MyConnections.A dd(ServerConnec tion)
Next
Return MyConnections
End Function
Private Function ReturnArrayInde xOfClient(ByVal PublicServerCon nection
As PublicServerStr uct) As Integer
Dim ServerConnectio n As New PrivateServerCo nnectionStruct
Dim MyIndex As Integer = 0
For Each ServerConnectio n In MyServerConnect ions
MyIndex += 1
If ServerConnectio n.Remote_host_n ame =
PublicServerCon nection.Remote_ host_name Then
If ServerConnectio n.Remote_port_n um =
PublicServerCon nection.Remote_ port_num Then
Return MyIndex
End If
End If
Next
'Cant find anythnig, so return ... -1
Return -1
End Function
End Class
Ok, this appears to be working. Its the wierdest thing I have seen yet in
..Net:
It appears that Directly manipulating the MyServerConnect ions 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 PublicServerCon nection As
PublicServerStr uct, ByRef MyClient As System.Net.Sock ets.TcpClient)
Dim Myindex As Integer =
ReturnArrayInde xOfClient(Publi cServerConnecti on)
If Not IsNothing(Myind ex) Then
Dim LocalPrivateSer ver As PrivateServerCo nnectionStruct
LocalPrivateSer ver = CType(MyServerC onnections(Myin dex - 1),
PrivateServerCo nnectionStruct)
LocalPrivateSer ver.client = MyClient
MyServerConnect ions(Myindex - 1) = LocalPrivateSer ver
End If
End Function
"gregory_ma y" <None> wrote in message
news:e%******** ********@TK2MSF TNGP10.phx.gbl. .. I want to prevent late binding of this statement:
MyServerConnect ions(Myindex).c lient = 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(MyServerC onnections(Myin dex), PrivateServerCo nnectionStruct) .Client = value
What is going on here? For reference, here is the struct definition:
Private Structure PrivateServerCo nnectionStruct Dim client As System.Net.Sock ets.TcpClient Dim Connected_To_Se rver As Boolean Dim Connected_User_ Name As String Dim Remote_port_num As Integer Dim Remote_host_nam e As String Dim MessageQueue As Queue End Structure
Dim MyServerConnect ions As New ArrayList This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
*********************************************************
Public Sub MailMerge(strQuery As String, strTemplate As String)
snip
Dim doc As Word.Document
Dim wrdApp As Word.Application
snip
Set wrdApp = New Word.Application
|
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 version of the MS Graph type
library. Up until now I have been walking them through
the process of setting the references to include their
version of MS Graph library.
My problem is that I can not seem to get the syntax
correct .. or perhaps...
|
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 As DAO.Workspace
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim rs As DAO.Recordset
|
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.
IT MUST BE LATE-BINDING THOUGH.
I need to be able to open an existing contact folder or create a new contact
folder, and add new contacts to it.
|
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 ...
Private Sub chkbxSelI_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
MsgBox("bingo for number " & sender.Tag.ToString)
End Sub
| |
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 integer
The integers in these arrays are actually pointers to different columns of
data in a text file.
|
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 that
describes this.
Here's the setup. We have a COM server, written in Python. For
completeness, here is the script:
----- testserver.py -----
import pythoncom
|
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 time (Early Binding) or run time (Late Binding). When you declare an Object Variable as a specific Data Type, you are using Early Binding so the verification can take place during compile time. When you declare a Variable of the generic Object Data...
|
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, txtQL10.DragDrop,
txtQL09.DragDrop, _
txtQL08.DragDrop, txtQL07.DragDrop, txtQL06.DragDrop,
txtQL05.DragDrop, _
txtQL04.DragDrop, txtQL03.DragDrop, txtQL02.DragDrop,
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |