Results 1 to 2 of 2

Thread: Select object from radiobutton

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Select object from radiobutton

    Hey,
    I have two labels on my form
    Label1
    Label2

    In the form load I generate a radiobutton for each label, with the text property being the name of the label.

    So two radiobuttons are made
    The first one will have text: Label1

    I have
    dim objStore as object
    Example:
    I select the first radiobutton (text: Label1)

    Then Label1 should be stored in objStore as object.

    So then I can do
    objStore.text = "test"

    Any help?

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Select object from radiobutton

    Sounds like you want to access a control by its variable name when all you have is a string that is equal to the variable name. The only way to do that is to use the forms controls collection to access a control by its name, and stick that into your variable. Note you shouldn't use type "object" to store a control, because it won't have the properties of a control you will want to set (like the .text property). You can use the actual type 'label' or the base type 'control' if you plan to store a control reference other than a label in objStore.

    Code:
            Dim objStore As Control
            objStore = Me.Controls(radiobutton1.text)
            objStore.Text = "test"

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