How can I close in code a visible but=nothing form2 instance

G

Guest

I put this question on a new thread because, in spirit, it is a new question.
I apologize that I have difficulty formulating the proper question.

My application performs matrix computations on data stored in arrays A, B,
…G. Populate subs fill a datagrid on instances of form2 with the elements of
the arrays (one form2 instance per array) so that the user can see what is in
the arrays. The caption of the form2 instances displays what array is being
displayed. For any given array, the visible representation needs to remain
available for review long after the completion of the populate sub. Also,
there can be only one form2 instance corresponding to each array - visible
at any one moment because the user needs to know what is in the arrays now,
not earlier.

I originally used a global constructor for each individual form2. As the
corresponding array was changed (say array A) the populate sub (say
populateA) would re-bind the form2 (say Matrix_A) to the new array data.

This approach worked well but it was very slow with huge arrays when they
were being repopulated or closed altogether (which in this implementation
involved setting the datagrid.datasource to nothing and hiding the form). It
was recommended that instead, I construct the Matrix_A repeatedly and
locally. This also works well and its fast. But it has the major drawback
that when I change the underlying array and repopulate the form2 I get
exactly two form2’s visible: the old one and the new one.

I know I can close the old one by physically clicking its close control. But
I cannot see how I can do this in code as – although it is visible – it no
longer exists (because the sub that created it has completed).

What’s a mathematician to do?
 
C

C-Services Holland b.v.

mark said:
I know I can close the old one by physically clicking its close control. But
I cannot see how I can do this in code as – although it is visible – it no
longer exists (because the sub that created it has completed).

What’s a mathematician to do?

Simple answer seems to dispose() it in the sub that created it in the
first place.
 
L

Larry Lard

mark said:
I put this question on a new thread because, in spirit, it is a new question.
I apologize that I have difficulty formulating the proper question.

My application performs matrix computations on data stored in arrays A, B,
...G. Populate subs fill a datagrid on instances of form2 with the elements of
the arrays (one form2 instance per array) so that the user can see what is in
the arrays. The caption of the form2 instances displays what array is being
displayed. For any given array, the visible representation needs to remain
available for review long after the completion of the populate sub. Also,
there can be only one form2 instance corresponding to each array - visible
at any one moment because the user needs to know what is in the arrays now,
not earlier.

I originally used a global constructor for each individual form2. As the
corresponding array was changed (say array A) the populate sub (say
populateA) would re-bind the form2 (say Matrix_A) to the new array data.

This approach worked well but it was very slow with huge arrays when they
were being repopulated or closed altogether (which in this implementation
involved setting the datagrid.datasource to nothing and hiding the form). It
was recommended that instead, I construct the Matrix_A repeatedly and
locally. This also works well and its fast. But it has the major drawback
that when I change the underlying array and repopulate the form2 I get
exactly two form2's visible: the old one and the new one.

I know I can close the old one by physically clicking its close control. But
I cannot see how I can do this in code as - although it is visible - it no
longer exists (because the sub that created it has completed).

What's a mathematician to do?

Since you want to be able to access your form2's programmatically, you
need to keep a reference to them (ie an object variable that points to
each one). When you recreate a form2 for a given array, that is the
time to close the previous form2 for that array.

How to keep these references? That depends - it could be as simple as
an array of 7 (A-G) elements, or if you already have a class that wraps
an array, you could put a form2 member in there. Skeleton for the first
:

(at a global level)
Dim DisplayForms() As Form2

(in global initialisation code)
DisplayForms = New Form2(7) {}

(when you want to display a Form2 for an array)
Dim newDisplayForm as New Form2
'set up the form
(iArrayIndex is from 1 to 7 depending on which array A to G you are
handling)
If Not DisplayForms(iArrayIndex) Is Nothing Then
'there is already a Form2 displaying this array, so close it
DisplayForms(iArrayIndex).Close
End If

'show the new form
newDisplayForm.Show
'and save a reference to it
DisplayForms(iArrayIndex) = newDisplayForm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top