Link to home
Start Free TrialLog in
Avatar of daghoff
daghoff

asked on

Different forms in the same array

I have some Arrays with Forms and that works fine. All the elements in any array are from the same Form (class).

I can access the Forms properties with Form(X).

I am now trying to craete a double array that will hold forms from diferent clases. I have defined the array like this
Friend Form(,) As Form.

And then later redefined it like this:
ReDim Form(NumFormSets, NumForms)

I create a form instance like this:
Form(1, 1) = New Form1()
Form(1, 2) = New Form2()
.........
Form(2, 1) = New Form1()
Form(2, 2) = New Form2()
.........

The purpose with all this is that I now can process all the forms using indexes in a very simple way.

But there seams to be some problems. One of them is that my array is of type Form. All the elements are of specific Form clases. I am trying to cast but dosent seam to get it right.

How can this be done?
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Why not use a Dictionary(Of Integer, Form) as a substitute to your array?
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
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
Unless your "specialized" forms don't inherit from Form, you shouldn't need to cast anything. Since the specialized version have Form as part of their type hierarchy, you should be able to use implicit type conversion without incident. The only time that I can see where you might run into problem is if you were trying to convert a Form1 to a Form2. In that case, I wouldn't expect a natural conversion because you would be talking about converting between "siblings" rather than base/derived.
*Oops...in my snippet, this:

    Dim F1 As Form

Should be:

    Dim F1 As Form1
Disregard my previous comment. I think I misunderstood what you meant by casting.