PC Review


Reply
Thread Tools Rate Thread

Create form from name

 
 
Shayne H
Guest
Posts: n/a
 
      26th Aug 2003
I was using the following code to create a form from its class name. It was
working then at some point I must have broken it, and now have no idea why
it will not work. The CreateInstance method returns <Nothing>

Class MyClass
Function OpenForm(ByVal FormName As String) As Form
Dim obj As Object
obj = Me.GetType.Assembly.CreateInstance(FormName, False)
Return CType(obj,Form)
End Function
End Class

--
Thanks for any help,
Shayne H


 
Reply With Quote
 
 
 
 
CJ Taylor
Guest
Posts: n/a
 
      26th Aug 2003
I've done something just like this just the other day.

I used Activator along with that and used GetExecutingAssembly() instead...

I have the code at work unfortunatly =(
"Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> wrote in message
news:(E-Mail Removed)...
> I was using the following code to create a form from its class name. It

was
> working then at some point I must have broken it, and now have no idea why
> it will not work. The CreateInstance method returns <Nothing>
>
> Class MyClass
> Function OpenForm(ByVal FormName As String) As Form
> Dim obj As Object
> obj = Me.GetType.Assembly.CreateInstance(FormName, False)
> Return CType(obj,Form)
> End Function
> End Class
>
> --
> Thanks for any help,
> Shayne H
>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      26th Aug 2003
Hello,

"Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> schrieb:
> I was using the following code to create a form from its class name. It

was
> working then at some point I must have broken it, and now have no idea why
> it will not work. The CreateInstance method returns <Nothing>


This works for me:

\\\
Dim objNewForm As Object = _
Activator.CreateInstance( _
Type.GetType("MyApplication.SampleForm") _
)
Dim frm As Form = DirectCast(objNewForm, Form)
frm.Show()
///

HTH,
Herfried K. Wagner
--
MVP · VB Classic, VB .NET
http://www.mvps.org/dotnet


 
Reply With Quote
 
CJ Taylor
Guest
Posts: n/a
 
      26th Aug 2003
That was a lot simplier than what I did...


"Herfried K. Wagner [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> "Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> schrieb:
> > I was using the following code to create a form from its class name. It

> was
> > working then at some point I must have broken it, and now have no idea

why
> > it will not work. The CreateInstance method returns <Nothing>

>
> This works for me:
>
> \\\
> Dim objNewForm As Object = _
> Activator.CreateInstance( _
> Type.GetType("MyApplication.SampleForm") _
> )
> Dim frm As Form = DirectCast(objNewForm, Form)
> frm.Show()
> ///
>
> HTH,
> Herfried K. Wagner
> --
> MVP · VB Classic, VB .NET
> http://www.mvps.org/dotnet
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a form command button that moves the form to a random record John S. Ford, MD Microsoft Access Forms 2 17th Jul 2009 04:01 PM
Create form similar to MS Access 2000 Help - Index form Cabby Microsoft Access Form Coding 2 8th May 2007 04:54 AM
If I create a form with the wizard and later decide I need to add another field do I have to re-create the form? Mister John Doe Microsoft Access Forms 3 2nd Jan 2005 06:17 AM
Re: Is there a way to create my own form wizard to create a series of. Suzanne S. Barnhill Microsoft Word Document Management 0 15th Sep 2004 05:22 PM
How can i create a hast table to to put my form in it,so I can find the each form easily? Serenaiad Microsoft Dot NET Framework 1 19th Mar 2004 10:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:19 PM.