Results 1 to 3 of 3

Thread: Passing an object name through a variable

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2000
    Location
    Dunstable, Beds, UK
    Posts
    3

    Post

    I need to be able to pass the name of an object into a variable and the use
    the variable to alter that objects properties...

    eg.

    Variable1 = ActMod1.Name

    Variable1.value = 15
    variable1.ID = 0012

    etc.

    Does anyone know how to do this???

  2. #2
    New Member
    Join Date
    Mar 2000
    Location
    Hull, PQ, Canada
    Posts
    7

    Post Classes, classes, classes...

    I believe the best way to do what you want to do is to create a class for your object (assuming this is possible in your situation). You can then declare a variable as your new class, which essentially creates a new instance of your object. You can then use that variable name to assign and retreive properties, methods, whatever.

    If you have never done this before, it's not that hard. You just add a class module to yuor project, create your class (you may have to look up how to do this - but it's easy enough), and then it will appear in the pop-up list as one of the available choices when you declare a variable.

    Hope this helps!

    JFDman

  3. #3
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    Here's an example without classes:
    Code:
    Private Sub Text1_LostFocus()
       Call ValidateText(Text1)
    End Sub
    
    Private Sub ValidateText(cControl as Textbox)  'or as Control
       If Len(cControl.Text) > 10 then
          cControl.Text = Left(cControl.Text, 8)
       End If
    End Sub
    This is only a quick example.



    Wade

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width