Results 1 to 5 of 5

Thread: For Each....?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    For Each....?

    How would I use the "For Each" to do the following....

    Dim counter as Integer

    For counter = 0 to myWidgetCollection.Count - 1
    MessageBox.Show(myWidgetCollection.Item(counter).Name)
    Next


    ***** I AM TRYING TO DO THIS EXAMPLE ...........

    http://msdn.microsoft.com/library/de...ctionClass.asp
    Last edited by birthjay; Jul 26th, 2004 at 10:02 AM.

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196
    Assuming that myWidgetCollection holds a myWidgetClass.
    I think you have to implement an IEnumerable Interface in myWidgetClass.

    this might help it's in C# but it should be easy enough to port
    Last edited by DeadEyes; Jul 26th, 2004 at 09:51 AM.

  3. #3
    Hyperactive Member dogfish227's Avatar
    Join Date
    Oct 2002
    Location
    GA
    Posts
    409
    VB Code:
    1. Dim widget as myWidgetClass
    2.  
    3. For each widget in myWidgetCollection.Items
    4. MessageBox.Show(widget.Name)
    5. Next

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830
    Thanks folks.....

    I am trying to create a forms collection in VB.NET because I am converting a VB6 project to VB.NET.

    I found this article:

    http://support.microsoft.com/default...b;EN-US;308537

    at Microsoft that supposedly tells you how to do it. I have a question about it.....

    On the part where it says..."Add and Remove Forms from the Collection".....where exactly is that code put? Is it in the module they are talking about etc....etc..

    Thanks!

  5. #5
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Declare your collection at module level as public.

    Then in form_load of each form add the form to the collection.
    In form_closing, remove the form from the collection.

    VB Code:
    1. Private Sub Form_Load(ByVal sender As Object,ByVal e As EventArgs) Handles MyBase.Load
    2. MyForms.Add(Me)
    3. End Sub
    4.  
    5. Private Sub Form_Closing(ByVal sender As Object,ByVal e As EventArgs) Handles MyBase.Closing
    6. MyForms.Remove(Me)
    7. End Sub

    I haven't tested this, but I'm pretty sure it could work.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

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