Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Dynamic Object Names ... how ?

Dynamic Object Names ... how ?

Scheduled Pinned Locked Moved Visual Basic
helpdata-structuresquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    swingheim
    wrote on last edited by
    #1

    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

    D D 2 Replies Last reply
    0
    • S swingheim

      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

      D Offline
      D Offline
      Divya Rathi
      wrote on last edited by
      #2

      Try This .. USe Load function. This function dynamically creates an object & loads it . Divya Rathi

      1 Reply Last reply
      0
      • S swingheim

        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

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        swingheim 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 Sub

        AddHandler[^] 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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups