Link to home
Start Free TrialLog in
Avatar of mancio
mancioFlag for Brazil

asked on

Use Multiple Forms

Why first form visible after last command in :

Public frm() as New Form1
Sub Main
  Redim frm(0)

 frm(0). Show

 Redim frm(1)
 frm(1).Show
....
 Unload frm(1)
set frm(1)=Nothing

,,,
unload frm(0)
set frm(0)=Nothing

Debug.Print Forms.Count resut 1 , I beleave but must be zero, no ?
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Try it like this.
'Public frm As New Form1 'Note that this is commented out
Sub Main()

Dim f As Form
 ShowForm

 ShowForm

For Each f In Forms
    If f.Tag = "1" Then
        Unload f
        Set f = Nothing
        Exit For
    End If
Next
For Each f In Forms
    If f.Tag = "2" Then
        Unload f
        Set f = Nothing
        Exit For
    End If
Next


Debug.Print Forms.Count ' resut 1 , I beleave but must be zero, no ?
End Sub
Sub ShowForm()
Dim frm As New Form1
frm.Show
frm.Tag = Forms.Count
End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mancio

ASKER

Thanks Martin Liss,
Please don't forget to choose one of my solutions as the answer.

In any case, you're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015