Dynamic Object Names ... how ?
-
The "eval" command does not exist in VB. I wish to do something that is possible in other languages:
For x As Integer = 1 to 10 Dim eval("obj" & x) As myObject eval("obj" & x).setting = value Next
An immediate answer is, "Create an array of objects!". Problem: the "myObject" throws events that I need to handle. If I create an array of "myObject"s, the objects can no longer throw events... even if they did, how would you handle them?Sub Handle_myObject() Handles ... ? End Sub
What would it handle? :confused: I am stuck on this one. Any help is appreciated. -- modified at 15:09 Thursday 2nd March, 2006 -
The "eval" command does not exist in VB. I wish to do something that is possible in other languages:
For x As Integer = 1 to 10 Dim eval("obj" & x) As myObject eval("obj" & x).setting = value Next
An immediate answer is, "Create an array of objects!". Problem: the "myObject" throws events that I need to handle. If I create an array of "myObject"s, the objects can no longer throw events... even if they did, how would you handle them?Sub Handle_myObject() Handles ... ? End Sub
What would it handle? :confused: I am stuck on this one. Any help is appreciated. -- modified at 15:09 Thursday 2nd March, 2006Try This .. USe Load function. This function dynamically creates an object & loads it . Divya Rathi
-
The "eval" command does not exist in VB. I wish to do something that is possible in other languages:
For x As Integer = 1 to 10 Dim eval("obj" & x) As myObject eval("obj" & x).setting = value Next
An immediate answer is, "Create an array of objects!". Problem: the "myObject" throws events that I need to handle. If I create an array of "myObject"s, the objects can no longer throw events... even if they did, how would you handle them?Sub Handle_myObject() Handles ... ? End Sub
What would it handle? :confused: I am stuck on this one. Any help is appreciated. -- modified at 15:09 Thursday 2nd March, 2006swingheim wrote:
I wish to do something that is possible in other languages:
Just because it's possible in other languages, doesn't make it a good programming practice.
swingheim wrote:
An immediate answer is, "Create an array of objects!".
It is the answer!
swingheim wrote:
Problem: the "myObject" throws events that I need to handle. If I create an array of "myObject"s, the objects can no longer throw events...
Not true! Create your array of objects, remembering to execute a
AddHandler
statement to manually wire up the event handlers.For i As Integer = 1 to 10
Dim newObject As New WhateverClass
AddHandler newObject.eventToHandle, AddressOf objectEventHandler
objArray(i) = newObject ' Or whatever your using to store the instances
Next
.
.
.
Private Sub objectEventHandler(parameters)
' blah, blah, blah
End SubAddHandler[^] docs. Don't forget to disconnect the handlers with RemoveHandler before the objects die! RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome