Reflection and Forms

Posted on 2007-08-01
Last Modified: 2010-04-23
I am using the following code to create a form based on a key value from a toolbar, is this the correct way of doing it. I have stitched it together from various exmaples. My concern starts with the first line is this right

   Dim asm As Assembly = Assembly.GetExecutingAssembly
            Dim formObj As Type = asm.GetType("Aquarius." & e.Item.Key)
            Dim formActivator As Object = Activator.CreateInstance(formObj)
            frm = DirectCast(formActivator, Form)
            If frm.Name.Substring(0, 4) = "View" Then
                frm.MdiParent = Me
            End If
Question by:rocky050371
    1 Comment
    LVL 96

    Accepted Solution

    1) If it works, go with it.

    2) It looks good to me.

    3) I would simplify a little:

        Dim formActivator As Form = DirectCast(Activator.CreateInstance(formObj), Form)

        If frm.Name.StartsWith("View") Then


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    761 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

    8 Experts available now in Live!

    Get 1:1 Help Now