Opening Forms

Is it possible to have a function to open a form by parming in the form Name as a string

Answer this question

Opening Forms

  • ejb111us

    Of course, anything is possible.

    However, it's up to you to implement it. I would suggest using one of the generic storage classes (vector, list etc..). I know one (or more) of them allows you to reference one of it's elements through a string value.

    Perhaps you could make such a variable for your program, then create a function that takes a string, and then sends the string to some generic container variable, and when it finds the element that is linked to that string, the Form.Show() method is called.

    :]


  • matlock85

    Agreed, default instances are not good practice and were really put back in in 2005 simply to aid VB6 (classic) developers in moving apps to .NET.

    If your writing applications from scratch, definately create your own instances.


  • scripteaze

    you should avoid using default instances and create a proper instance of an object and use that. It's recommended and better practice. In addition you could use the Application.OpenForms() collection and get hold of a form that may already be open and use that. Example:

    Dim theForm as Form = Application.OpenForms("FormName")

    if theForm is nothing = false then

    'we got hold of that form

    end if



  • Nfrf

    It's simpler than that.....

    Private Sub OpenForm (byval FormName as string)

    Select Case "Lassie"

    FormLassie.Show

    Select Case "Timmy"

    FormTimmy.Show

    End Select

    End Sub



  • Opening Forms