Solved

Use Multiple Forms

Posted on 2016-08-23
4
60 Views
Last Modified: 2016-08-24
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 ?
0
Comment
Question by:mancio
  • 3
4 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41767058
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

0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41767214
I just realized what the problem is with your code. You were Redim-ing without using the Preserve keyword. That caused the form array to be rebuilt rather than just added to. This works. See line 7.

Public frm() As New Form1
Sub Main()
  ReDim frm(0)

 frm(0).Show

 ReDim Preserve 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 ?
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:mancio
ID: 41767422
Thanks Martin Liss,
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 41767674
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
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question