Is there any way to like 'dim obj as _______' and then control real objects with it? Like...
obj = text1
obj.text = "blah"
..and it work?
Is there any way to like 'dim obj as _______' and then control real objects with it? Like...
obj = text1
obj.text = "blah"
..and it work?
As already demonstrated, a generic object variable can point at a real control on the same form. For a networked chess game you should not try to transfer a live control reference between machines. Instead send a small, well‑defined message (an action + target + data), then translate that message into a local operation (update the game model, then refresh the UI). That keeps the protocol stable and avoids brittle, insecure logic that tries to manipulate remote UI objects directly.
A simple VB6 handler pattern (receive a delimited command, find the control, set a property) looks like this:
' Example incoming: "SET|txtStatus|Text|White to move"
Private Sub HandleMessage(msg As String)
Dim parts() As String
parts = Split(msg, "|")
If UBound(parts) < 3 Then Exit Sub
Dim cmd As String, ctrlName As String, propName As String, val As String
cmd = parts(0): ctrlName = parts(1): propName = parts(2): val = parts(3)
' Implement whitelists before changing anything:
If Not IsAllowedControl(ctrlName) Or Not IsAllowedProperty(propName) Then Exit Sub
Dim ctrl As Object
On Error Resume Next
Set ctrl = Me.Controls(ctrlName)
If ctrl Is Nothing Then Exit Sub
CallByName ctrl, propName, VbLet, val
On Error GoTo 0
End Sub Practical tips: (1) Prefer sending game moves (e.g. "MOVE|e2|e4") and validate moves against your game model before touching the UI. (2) Use a framing scheme for Winsock (length prefix or delimiter) so partial packets don’t confuse parsing. (3) Whitelist allowed controls and properties to avoid a remote client changing arbitrary UI state. (4) If you need full object state transfer, serialize the state (custom text, XML/JSON) and rehydrate on the other side — remote COM/DCOM invocation is possible but complex and generally not worth it for a simple game.
Jump to Post— Comatose 290Yes. It's not generally done, and will probably make your code more difficult to follow and understand when you are trying to add/update things later..... beyond that, as was mentioned in another thread, you'll be using more memory (to create an object variable to an object that already exists) to …
Yes. It's not generally done, and will probably make your code more difficult to follow and understand when you are trying to add/update things later..... beyond that, as was mentioned in another thread, you'll be using more memory (to create an object variable to an object that already exists) to work with data and store data that already exists in the object. HOWEVER, it CAN be done. Here is a small example that I just built, with nothing but a form and a textbox..... in the form_load, I put this:
Dim x As Object
Set x = Text1
x.Text = "hi" And the .text property of the text1 textbox has changed to "hi". Again, I advise against this method for a large number of reasons, but certainly it can be done, and will work.
Is there a way to do like...
winsck1.senddata ("Text1")
dim x as object
winsck1.getdata RecData
set x = RecData
x.text = "hi" because I can't seem to get it to work.
No... recdata is a variable that will contain information received from a socket. It is, in no way shape or form, an object. I don't understand what you are doing, or trying to get accomplished, but let me lay out how this reads:
1. Send The Literal String (send the word) "text1" across the network
- if you are trying to send the data that the user typed into text1
-across the network, you would do winsck1.sendata text1.text 2. declare X as an object variable
3. read data from the network, and store it in a variable called RecData
4. Try to set an object variable to the value stored in RecData
-set binds a variable to the specified object.
-you can not bind an object to a variable value....
-the RecData variable has no .text property, no enabled property
or any other kind of property.... it's just a variable that holds a
value, not an object variable.
5. Try to set the .Text Property Of the Object Variable X to "hi"
-Since You can't set X (an object variable) to a scalar variables
value, this will fail, if the line before it did not terminate the
program due to errors.
I do understand, however, what you are trying to do. You want to send an object reference across the network, and then use that object reference on the receiving machine. The problem is, the receiving machine wouldn't have that object reference.....
Well, it's kind of like a chess game. I was trying to just send the peice the other person selected and turn it into an object, but I guess I just have to keep using alot of if's, heh.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.