VB5/6 have a feature that makes it unnecessary to load a form [class] before using it. With COM Automation, as much as accessing any function of the form, will automatically load it into memory. That's why we don't have to code:
Load MyForm
MyForm.Show
we just call
MyForm.Show
even if it had never been loaded before. To see this behaviour for yourself, just paste this into any .frm file:
Private Sub Form_Load()
MsgBox Me.Name & " is loading."
End Sub
Private Sub Form_Unload(Cancel As Integer)
MsgBox Me.Name & " is unloading."
End Sub
You can also set a global variable in those events, to keep track of whether the form is currently loaded or not. Checking Enabled or Visible or what not, will only load the form if it isn't already. I had such a nightmare experience once, when I was called on to fix a project with over 10 forms in it; modals and non-modals were mixed, multiple instances, what a job.
Unfortunately, unloading does not always work as expected, because if any COM object still holds a reference to anything in the form, it will not be unloaded. This sort of thing is a vexing problem with all automatic-object languages, especially when they pretend pointers don't exist (you forfeit control). That's because it's extremely difficult for the language to know when you no longer intend to keep working with an object. Whether reference counting, garbage collection, or whatever means is employed, it's always a calculated compromise. Best is to know when to manually destroy objects, but most programmers find it difficult to do. Languages like VB, Python, Java, C#, and others, attempt to do this for us, but it makes dealing with these things at any serious level difficult and very confusing. Enough of my sermon :)