Solved

Different forms in the same array

Posted on 2012-03-11
5
130 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
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:nepaluz
Comment Utility
Why not use a Dictionary(Of Integer, Form) as a substitute to your array?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
"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 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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 85

Expert Comment

by:Mike Tomlinson
Comment Utility
*Oops...in my snippet, this:

    Dim F1 As Form

Should be:

    Dim F1 As Form1
0
 
LVL 74

Expert Comment

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now