How many test form is open ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: How many test form is open ?

  1. #1
    Join Date
    Sep 2007
    Posts
    182

    How many test form is open ?

    I suppose there are many programs of the form, I can determine how much the order form is opened and the name of the form is not open? Who can share me with example, thanks

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,074

    Re: How many test form is open ?

    Code:
    Private Sub Command3_Click()
    
    Dim NumberOfForms As Integer 'Variable to hold number of open forms
    NumberOfForms = Forms.Count 'Count all open forms
    MsgBox NumberOfForms 'Display variable
    
    Dim intCounter As Integer
    
    For Each Form In Forms 'Loop through Forms collection
        MsgBox Forms(intCounter).Name 'Display each open form's name
       intCounter = intCounter + 1
    Next
    End Sub

  3. #3
    Join Date
    Sep 2007
    Posts
    182

    Re: How many test form is open ?

    Quote Originally Posted by HanneSThEGreaT View Post
    Code:
    Private Sub Command3_Click()
    
    Dim NumberOfForms As Integer 'Variable to hold number of open forms
    NumberOfForms = Forms.Count 'Count all open forms
    MsgBox NumberOfForms 'Display variable
    
    Dim intCounter As Integer
    
    For Each Form In Forms 'Loop through Forms collection
        MsgBox Forms(intCounter).Name 'Display each open form's name
       intCounter = intCounter + 1
    Next
    End Sub

    1. form that is open can have a number of these?

    2. closed form series open with error
    For Each frm In Forms
    If frm.Name <> Me.Name Then
    If frm.MDIChild = True Then
    MDIMainForm.RemoveChild frm.Name ' Error here
    End If
    End If
    Next
    Set frm = Nothing

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,074

    Re: How many test form is open ?

    I don't understand your last question. Mind rephrasing it a bit, please

  5. #5
    Join Date
    Sep 2007
    Posts
    182

    Re: How many test form is open ?

    1. Have i want to order of forms openning ?
    2. I want to close all form openning but not and warning error
    For Each frm In Forms
    If frm.Name <> Me.Name Then
    If frm.MDIChild = True Then
    MDIMainForm.RemoveChild frm.Name ' Error here
    End If
    End If
    Next
    Set frm = Nothing

  6. #6
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,784

    Re: How many test form is open ?

    What is the error and what is it you are trying to do?
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Sep 2007
    Posts
    182

    Re: How many test form is open ?

    Quote Originally Posted by HanneSThEGreaT View Post
    I don't understand your last question. Mind rephrasing it a bit, please
    The my program has very many forms, but there are 2 main types MDIForm and FormChild. when I open many FormChild into MDIForm, instead I close each FormChild. I want close many FormChild same time instead closing FormChild one by one. Do you understand ?

  8. #8
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,874

    Re: How many test form is open ?

    Yes. But, VB6 can't do that. You'd have to close the MDIForm that contained the Children.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,784

    Re: How many test form is open ?

    I have never saw this used
    Code:
    MDIMainForm.RemoveChild frm.Name ' Error here
    If I was wanting to unload the children of a mdi form I would use the Unload method
    Always use [code][/code] tags when posting code.

  10. #10
    Join Date
    Sep 2007
    Posts
    182

    Re: How many test form is open ?

    Quote Originally Posted by DataMiser View Post
    I have never saw this used
    Code:
    MDIMainForm.RemoveChild frm.Name ' Error here
    If I was wanting to unload the children of a mdi form I would use the Unload method

    if I use Unload the following Unload I have must to put the correct name of FormChild. eg MDIForm have Form1, Form2, ... Formn:

    unload Form1
    unload Form2
    ...
    unload Formn


    Now, I want to replace the code above with:

    Dim frm As Form
    ' Close many FormRemoveChild
    For Each frm In Forms
    If Me.Name <> frm.Name Then ' Me.Name is MDIForm and frm.Name is Form1, Form2, ...., Formn
    Unload frm.Name ' Error here
    End If
    Next
    Set frm = Nothing

    What should I do ?
    Last edited by dongtrien; August 11th, 2013 at 02:11 AM.

  11. #11
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,784

    Re: How many test form is open ?

    It would help if you would tell us what the error message is rather than just saying error here.

    At any rate the problem is that you are using unload incorrectly
    it should be

    Code:
    unload frm
    when you add the .name you are telling it to unload the name property of the form which is a string and of course that is not valid resulting in a type mismatch

    Example:

    Create a new project with 2 forms form1 and form2
    Add a button to form 1 and use the default name of command1

    paste this code in form1 code window replacing any that is there already
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim frm As Form
    For Each frm In Forms
        If frm.Name <> Me.Name Then
            Unload frm
        End If
    Next
    End Sub
    
    Private Sub Form_Load()
    Dim x As Integer
    Dim frm As Form
    For x = 1 To 10
        Set frm = New Form2
        frm.Show
    Next
    
    
    
        
    End Sub
    run the program then click the button

    it should create 10 copies of form 2 and then close them when you click the button leaving form 1 in tact
    Last edited by DataMiser; August 11th, 2013 at 02:25 AM.
    Always use [code][/code] tags when posting code.

  12. #12
    Join Date
    Sep 2007
    Posts
    182

    Re: How many test form is open ?

    Ok, thank you very much

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center