Results 1 to 3 of 3

Thread: Forms collection - Can be used as a tutorial - SOLVED

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    New York
    Posts
    165

    Question Forms collection - Can be used as a tutorial - SOLVED

    Hi,

    I am creating an application which has an MDIForm as the startup form. From here, the user clicks on a 'Get Content' button, which calls the GetContent() procedure, and x amount of forms are created depending on how many documents are open in Word.

    For this example, we will say 3 documents are open in Word, therefore when the user clicks on the 'Get Content' button, 3 forms are created:

    '***********
    'Create forms:
    '***********
    Public Sub GetContent()
    Dim f1 as Form1
    Dim myFormCollection As New Form1Collection()

    'Remove all current forms:
    If myFormCollection.Count > 0 Then
    myFormCollection.Clear
    End If

    For i = 1 To intDocCount 'Number of Word docs. open
    f1 = New Form1() 'Create new Form
    f1.MdiParent = Me
    f1.Text = objWord.Documents.Item(i).FullName
    myFormCollection.Add(f1) 'Add the Form to the Collection class.
    Next
    End Sub

    To keep track of the forms, I am using the Form1Collection class which I created. Every time a Form is created it is added to the class: myFormCollection.Add(f1)

    '*********************
    'Class: Form1Collection
    '*********************
    Public Class Form1Collection
    Inherits System.Collections.CollectionBase

    Public Function Add(ByVal myForm1 As Form1)
    List.Add(myForm1)
    End Function

    End Class

    The problem I am having is with the section of GetContent() that removes all current forms. This is designed to protect the user if they click on the 'Get Content' button more than once. Instead of lots of forms building up on top of each other, this clears all current forms. However, even though I am using the .Clear method, the forms build up on top of each other. Ie. If 3 Word documents are open and the user keeps clicking 'Get Content', the forms increment in 3, 6 then 9 etc.

    I know this is a bit long, but as a complete newbie (like most of us to this, any help really would be much appreciated

    Any ideas?

    Thanks

    Chris
    Last edited by csf; Apr 12th, 2002 at 11:24 AM.

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