Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Names of Object in a Frame

Status
Not open for further replies.

domt

Programmer
Mar 13, 2001
115
0
0
US
Can anyone suggest a method/procedure/code for getting a list of the Names of Objects in a frame when the user clicks on any object in that Frame?
I'm working on a programs that presents several frames each containing different Objects, and the program must process those objects.
Thanks for any help.
 
If your objects are on the Frame (and not just located over the frame), you may use .Container property of the objects to detect if the object is on the same container or not.

Code:
Dim Cntl As Control

For Each Cntl In Me.Controls
    If Cntl.Container.Name = "fraMyFrame" Then
        'Do whatever you want to Cntl
    End If
Next

That should give you a clue......

Have fun.

---- Andy
 
Andy
Thanks for your responce.
I know what the object in a frame is by clicking on it. Coding also idetifies the particular frame using the identity of the selected object. From learning the frame name, then, by coding I want to identify other frames and learn which objects are in those frames. I have code to do that.
So I need code to list all the objects in frames identified by code.
I can handle all the coding involved except code that lists the object in a frame the code selects.
I hope I've made myself clear.
Thanks again for your interest.
 
If I understand you correctly, you will have the name of a frame stored in a variable (the frameName variable, in this example) and are looking to output all controls on the form that are in the frame. Since you haven't indicated how you want to do this, I'll use a ListBox to output for this example. You could try something like:

Code:
Dim ctl As Control
For Each ctl In Me.Controls
    If ctl.Container.Name = frameName Then
        List1.AddItem ctl.Name
    End If
Next


-V
 
<I hope I've made myself clear.

Nope, sorry, I'm more confused than ever. Seems to me, all you need to do is find out the names of the controls (you call them objects, and indeed they are, but objects that you can see are called controls) in a given frame, when the user clicks on any of the controls in that frame.

You'll notice that both examples are the same. That's because it's how to do what you've asked to do. Either that, or we don't understand what you're asking for. I'm going to assume that we do understand, and explain the code given a bit.

Now, if you look, you'll notice that any control has a "Container" property. For a control that isn't in a frame, this property will be the form. (For example, the Container property of the frame will be the form.) If a control is in the frame, its Container property will be the frame.

The code given looks at every control on the form (Me.Controls is a collection of all the controls on the form), whether or not it's in the frame in question. If the control is contained in the frame (if its Container property--itself an object, so it has properties too--has a Name property that is the name of the frame in question), then it meets the condition in the loop and you can do whatever you want to do.

All right. Now, I'm going back over your second post, and I'll see if I can get more specific about what I don't understand.

>I know what the object in a frame is by clicking on it.
Ok, me too.
>Coding also idetifies the particular frame using the identity of the selected object.
You can do this with one line by evaluating the Container.Name property of the selected object. I suspect your "coding" has rather more than one line, but I could be wrong.
>From learning the frame name, then, by coding I want to identify other frames and learn which objects are in those frames. I have code to do that.
You haven't made clear what you mean by "identify other frames" in code. But, once you have identified the frame you want to use, the code given above will allow you to identify which objects are in those frames. Again, I suspect that the code that you have to do that is significantly more complicated. I would consider abandoning it if so.
>So I need code to list all the objects in frames identified by code.
Given the name of the frame you can use the above code.
>I can handle all the coding involved except code that lists the object in a frame the code selects.
That's the code you've been given.

One more thing. If you have lots of frames and lots of controls, and you perform this procedure often, you might want to evaluate all the frames and all the (other) controls during form load and copy their names into either an array or an ADO recordset object, and then use that in subsequent operations. Either are quicker to access than the controls collection.

HTH

Bob
 
Thanks, guys, for all your responses and interest.
I have managed to work around the problem by accessing the array item numbers of the elements I'm working with. While the solution "aint elegent", it works, and the computer doesn't mind the extra labor.
I'll have to study uo on VB collections. I have many Visual Basic refererence books but there is a paucity of information on this topic.
Thanks again.
domt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top