Results 1 to 6 of 6

Thread: Seek and destroy search

  1. #1

    Thread Starter
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727

    Arrow

    Hi all,

    I need to seek for the content of a label in all open forms of an MDI. To be more specific, of all the child forms that have been created within the MDI, I need to look for the forms that have a label named MyLabel and return the content of it.

    These forms have all been created using the following code:

    Code:
    Dim FrmD As TemplateForm
    Set FrmD = New TemplateForm
    FrmD.Show
    where of course TemplateForm is a child form.

    Does someone of you have a good seek and destroy code for this?

    Best regards to you all, let the forum live!

    W.
    When your car breaks down,
    close all windows and retry

    => please rate all users posts! <=

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Loop through the Forms collection and with those forms whose .Parent is "MyForm", loop through the controls for a Label control.

    Or have I got it totally wrong? I am a bit rusty on MDI...

    Cheers,

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

  3. #3

    Thread Starter
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    i believe that could work, still do you have a code example to give?

    Thanks,

    W.
    When your car breaks down,
    close all windows and retry

    => please rate all users posts! <=

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You should have another collection to which you add to/remove childs from the mdiparent, then you can loop trough that collection. The controls on the forms are in controls object which you can loop trough using for each statement. use name property to catch the label name
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    Talking

    Would you believe I have managed to work it out.

    The following code looks through the forms collection, and then through all the controls for that form and will display the caption of the control Label3.

    Be aware that the Forms collection only contains the forms that are loaded, not forms that are part of the project and not yet loaded. Also the comparison on the Label3 name IS case sensitive so it will not see label3 as opposed to Label3.


    Code:
       Dim i As Integer
        Dim ctrl As Control
    
       For i = 0 To Forms.Count - 1
          
          MsgBox Forms(i).Name
          For Each ctrl In Forms(i).Controls
            If ctrl.Name = "Label3" Then
                MsgBox ctrl.Caption
            End If
          Next
       Next i
    I am still amazed I have worked it out.
    Hope this helps.


    Things I do when I am bored: DotNetable

  6. #6

    Thread Starter
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    WOW! That looks like pure gold to me I just have to substitute your

    MsgBox Forms(i).Name

    with the filter on the form name ("TemplateForm") done with a simple conditional IF, and then if this works I'm done!

    I'll try it tonight, thanks a damn lot,

    W.
    When your car breaks down,
    close all windows and retry

    => please rate all users posts! <=

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