CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Objects names in frames

    Using macro in Excell 2002, is there any way to use the real names of the objects inside frames?

    It's really confusing when you have to use
    Code:
    Frame1.Controls.Item(1).Value
    even after naming correctly the controls.

    Thanks
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  2. #2
    Join Date
    Jan 2004
    Location
    San Diego
    Posts
    148

    Re: Objects names in frames

    Yes. You should be able to reference an object something like the following.
    Code:
    Frame1.txtFile.Value
    Frame1.opt1.Value
    You may need to provide a copy of the code to let us help you find the problem, if these kinds of statements aren't working.

    You may also want to try refering to the object plainly by name. Sometimes the app will know what you are refering to and not need the reference to the frame object as well. i.e.
    Code:
    txtFile.Value
    opt1.Value
    Last edited by NatThoelecke; September 22nd, 2005 at 12:56 PM. Reason: Thought of something else that might help
    Death is life's special way of telling you you're fired.

    For I do not seek to understand in order to believe, but I believe in order to understand. For I believe this: unless I believe, I will not understand. - Anselm of Canterbury (1033–1109)

  3. #3
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Objects names in frames

    NatThoelecke,
    thanks for your answer, but no, I cannot. I'm using Excell 2002, perhaps the problem is there ...

    An example follows. The second line on the macro does not execute.

    Thanks again.
    Attached Files Attached Files
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  4. #4
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Objects names in frames

    I don't know if the CallByName() function is available to you, but perhaps if it is you can use that.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  5. #5
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Objects names in frames

    Wizbang,
    sorry but I don't see how CallByName -yes, I have it available- sould help me in my problem.

    All I want is to use a control inside a frame by its name ...

    Say something so simple as
    Code:
    MsgBox (Frame1.Controls.Item(0).Value)
    MsgBox (Frame1.mycheckbox.Value)
    The first statement works fine. The second does not even if the button is named MyCheckBox. Simply, VB does not recognize the name of the object when it is inside a frame.

    To use CallByName I have to put an object inside it ...
    Code:
    CallByName(Frame1.Controls.Item(0), ...
        ' would work, but it doesn't solve my problem
    Thanks anyway.
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  6. #6
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Objects names in frames

    So, even if you use MyCheckBox without accessing the frame, it still doesn't work? That is weird, and obviously related to VBA or excel somehow.

    Suppose you place the control outside the frame at design time, and place it inside the frame at runtime, either via API or the Container property?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  7. #7
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Objects names in frames

    Quote Originally Posted by WizBang
    So, even if you use MyCheckBox without accessing the frame, it still doesn't work? That is weird, and obviously related to VBA or excel somehow.
    I'm not sure of understanding your sentence. What do you mean by "without accessing the frame"?
    I'm not accessing anything.
    Take a look at the code ... I just want to get the value of a property ...
    Supose the checkbutton were placed outside the frame. I could do
    Code:
    MsgBox(MyCheckButton.Value)
    In theory, with the button inside the frame it should be
    Code:
    MsgBox(Frame1.MyCheckButton.Value)
    but it does not work, VB does not recognize the name of the object.

    Quote Originally Posted by WizBang
    Suppose you place the control outside the frame at design time, and place it inside the frame at runtime, either via API or the Container property?
    Well, I was trying to do something simpler than Frame1.Controls.Item(0).Value ... but moving the object at run time ... uffff

    It's just a matter of coding simplicity and clarity.

    Thanks
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  8. #8
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Objects names in frames

    Quote Originally Posted by DeepButi
    I'm not sure of understanding your sentence. What do you mean by "without accessing the frame"?
    I'm not accessing anything.
    I mean, in vb you don't need to specify the frame to get at the controls in it. I've never done that, so I don't even know if it is supposed to work. So, try just MsgBox(MyCheckButton.Value). Nevermind that it is inside a frame. Does this work?
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  9. #9
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Objects names in frames

    Quote Originally Posted by WizBang
    I mean, in vb you don't need to specify the frame to get at the controls in it. I've never done that, so I don't even know if it is supposed to work. So, try just MsgBox(MyCheckButton.Value). Nevermind that it is inside a frame. Does this work?
    WizBang,
    no, it does not work. And yes, you need to specify the frame. If you don't specify the frame, you are referencing objects outside the frame.

    You can create two identical objects with the same name, one at the "Sheet" level and another one at the "Frame" level.

    The first one's name will be, assuming it is on Sheet1, Sheet1.MyButton although you can use MyButton without qualifying it, provided the scope of the statement is adequate.

    The second one's name should be Sheet1.Frame1.MyButton Again, with an appropiate scope you can use Frame1.MyButton or MyButton

    The problem is ... this is in theory, because I cannot use objects inside frames using its name, I'm only able to use Frame1.Objects.Item(n)

    Are you using objects inside frames? Could you post an example? In wich version of Excell/VB (I'm using Excell 2002/VB6.3) ?

    Thanks a lot
    Last edited by DeepButi; September 26th, 2005 at 09:27 AM.
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  10. #10
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Objects names in frames

    In VB (not excel), there is no need to specify the frame because all the controls are seen at form level. I've never used excel, so I don't know what differences you might encounter. Suppose you create a UserControl, and expose the controls that way? Then you can create whatever methods and means of access you need.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  11. #11
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Objects names in frames

    WizBang,
    yes, you're right, I work usually with VB.NET and never found such a problem, but now I'm working on that particular combination of Excell2002/VB6.3 and I'm really surprised of not "seeing" the objects anywhere. Not at the Sheet (form) level, neither at the frame level.

    I'm forced to use frames because I use several sets of radio-buttons. If I put all of them at the Sheet level, they group together and only one can be selected, so I need to put each set in a separate frame.

    Anyone using controls inside frames on Excell2002/VB6.3 out there?

    Thanks for all your answers.
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

  12. #12
    Join Date
    Dec 2001
    Posts
    6,332

    Re: Objects names in frames

    I seem to recall the forms 2.0 option buttons having a property that allowed them to be grouped without using a frame. They might come with excel, but I'm not sure. However, the forms 2.0 controls are so buggy, they are usually not worth using. Also they aren't redistributable.

    I still think a UserControl would be the way I'd do this.
    Please remember to rate the posts and threads that you find useful.
    How can something be both new and improved at the same time?

  13. #13
    Join Date
    Dec 2003
    Location
    St. Cugat - Catalunya
    Posts
    441

    Re: Objects names in frames

    WizBang,
    group property! of course, that's it. Stupid of me, always doing things the complex way

    That solves my problem (although how to use objects in frames by its name still remains, but I don't need it anymore).

    Thanks a lot
    Did it help? rate it.

    The best conversation I had was over forty million years ago ... and that was with a coffee machine.

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

Featured