Home All Groups Group Topic Archive Search About
Author
24 Jan 2006 2:16 AM
Martin
VB2005

Hi!

I know there is an OpenForms collection, but is there also a collection of
all forms defined in an app?
I have built a "shortcut" bar and now need to translate a string variable
"Form1" to an object name Form1.

I thought I'd simply loop through a collection until the string value equals
the form.name. But I cannot find an applicable collection....

Ideas anyone?

Tia,
Martin

Author
24 Jan 2006 9:32 AM
Cor Ligthert [MVP]
Martin,

Seen as disproportion by probably all longer using VBNet developpers in this
newsgroup, a part from the My namespace.

As I have read yesterday so nice described by Herfried in another message,
as "faking VB6 behaviour in VBNet".

http://msdn2.microsoft.com/en-us/library/87y2hdsf.aspx

I hope this helps,

Cor
Author
24 Jan 2006 10:59 AM
Martin
Hi Cor,

Thanks for your response. I have been looking at the My.Forms object, but I
didn't see how I could use it, since it doesn't seem to have an enumerator.

I have the form name in a string variable and I thought to make a function
something like this:

Private Function OpenForm(ByVal FormName as String) as Boolean
    For Cntr=0 to My.Forms.Count - 1
         If My.Forms(Cntr).Name = FormName then
            My.Forms(Cntr).Show()
            Exit Function
        End If
End Function

In other words, I need to convert a form name in a string to an object....

Tia,
Martin







Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:eb803jMIGHA.1088@tk2msftngp13.phx.gbl...
> Martin,
>
> Seen as disproportion by probably all longer using VBNet developpers in
> this newsgroup, a part from the My namespace.
>
> As I have read yesterday so nice described by Herfried in another message,
> as "faking VB6 behaviour in VBNet".
>
> http://msdn2.microsoft.com/en-us/library/87y2hdsf.aspx
>
> I hope this helps,
>
> Cor
>
>
Author
24 Jan 2006 6:45 PM
Herfried K. Wagner [MVP]
"Martin" <x@y.com> schrieb:
> I know there is an OpenForms collection, but is there also a collection of
> all forms defined in an app?
> I have built a "shortcut" bar and now need to translate a string variable
> "Form1" to an object name Form1.

You may want to use 'Activator.CreateInstance' to instantiate the forms.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
25 Jan 2006 1:54 PM
Martin
Hi Herfried,

Thanks for your reply. This sounds like the function I need, but I can't get
it to work...

Dim FormName as string = "frmPatient"
Activator.CreateInstance(FormName, System.Windows.Forms.Form)

This is one of the many things I tried... Unfortunately the Help file is not
very "Helpful"...

What am I doing wrong?

Tia,
Martin


Show quoteHide quote
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
news:uvU$ZZRIGHA.1288@TK2MSFTNGP09.phx.gbl...
> "Martin" <x@y.com> schrieb:
>> I know there is an OpenForms collection, but is there also a collection
>> of all forms defined in an app?
>> I have built a "shortcut" bar and now need to translate a string variable
>> "Form1" to an object name Form1.
>
> You may want to use 'Activator.CreateInstance' to instantiate the forms.
>
> --
> M S   Herfried K. Wagner
> M V P  <URL:http://dotnet.mvps.org/>
> V B   <URL:http://classicvb.org/petition/>
Author
25 Jan 2006 2:19 PM
Martin
Hi Herfried,

I got it! No thanks to VS2005 help system, but your very informative website
dotnet.mvps.org

This is the code that made it work (maybe someone else would be interested
as well):

Private Sub ShowFormByName(ByVal FormName As String)
    Dim frm As Form
    Dim tpe As Type
    tpe = Type.GetType("appEspital." & FormName)
    frm = DirectCast(Activator.CreateInstance(tpe), Form)

    frm.MdiParent = Me
    frm.Show()

End Sub

Thanks again,
Martin

Show quoteHide quote
"Martin" <x@y.com> wrote in message
news:%23dNWTbbIGHA.3000@TK2MSFTNGP14.phx.gbl...
> Hi Herfried,
>
> Thanks for your reply. This sounds like the function I need, but I can't
> get it to work...
>
> Dim FormName as string = "frmPatient"
> Activator.CreateInstance(FormName, System.Windows.Forms.Form)
>
> This is one of the many things I tried... Unfortunately the Help file is
> not very "Helpful"...
>
> What am I doing wrong?
>
> Tia,
> Martin
>
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
> news:uvU$ZZRIGHA.1288@TK2MSFTNGP09.phx.gbl...
>> "Martin" <x@y.com> schrieb:
>>> I know there is an OpenForms collection, but is there also a collection
>>> of all forms defined in an app?
>>> I have built a "shortcut" bar and now need to translate a string
>>> variable "Form1" to an object name Form1.
>>
>> You may want to use 'Activator.CreateInstance' to instantiate the forms.
>>
>> --
>> M S   Herfried K. Wagner
>> M V P  <URL:http://dotnet.mvps.org/>
>> V B   <URL:http://classicvb.org/petition/>
>
>