Solved

Different forms in the same array

Posted on 2012-03-11
5
135 Views
Last Modified: 2012-03-22
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?
0
Comment
Question by:daghoff
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 37707360
Why not use a Dictionary(Of Integer, Form) as a substitute to your array?
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 37707422
"I am trying to cast but dosent seam to get it right."

...and what are you doing to cast it?

Should be something like:
    If TypeOf Form(2, 1) Is Form1 Then
        Dim F1 As Form = DirectCast(Form(2, 1), Form1)
        ' ... do something with "F1" ...
    End If

Open in new window


*I wouldn't use "Form" as the name of your Array since that is a pre-defined class name.  Change that to something else!
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37707471
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.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 37707480
*Oops...in my snippet, this:

    Dim F1 As Form

Should be:

    Dim F1 As Form1
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37707580
Disregard my previous comment. I think I misunderstood what you meant by casting.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

734 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