Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2004

Tip: Looking for answers? Try searching our database.

About Creating Objects Dynamically

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tom - 28 Oct 2004 03:11 GMT
Hi All :

I'm VB.Net Beginner I try to create object Dynamically :

In my testing, I create 2 .net project
One is MyApp (Type is windows application) with one button name "Button1"
The another one is "prj01" (Type is Class libary) with one public Class name
"dbLib"

In this prj01.dbLib I create the simple code "

Public Class dbLib
   Public Function SendMsg()
       MsgBox("a")
   End Function
End Class

and success to compile.

In the MyApp.Form1 I create the following Simple code :

Public Class Form1
   Inherits System.Windows.Forms.Form
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
           Dim oCar As Object
          Dim ty As Type = Type.GetType("prj01.dbLib")
           oCar = Activator.CreateInstance(ty)
           oCar.SendMsg()

   End Sub
End Class

However , while I run the project , The object "ty" return NOTHING.

And show error "Value Cannot be Null"

How can fix it

Thanks
Charlie - 28 Oct 2004 05:31 GMT
If you have a class in a separate project, make sure the start up project has
a reference to that project in the references section of the solution tree
view.

'******code******

Public Class GetThis
Public Sub GetThisMessage(ByVal Message as String)
MessageBox.Show(Message)
End Class

'*****end of code******

The code is simpler that what you were trying to do.
Inside your button event handler, write the following code

'******code*******

Dim GT as New Proj1.GetThis
GT.GetThisMessage("Go Sox")

'*****end of code*******

The new keyword allows you to construct an instance of the class from the
class, which can be thought of as a template.

Once you have the instance, you can manage the properties of the instance,
and use its methods.

www.charlesfarriersoftware.com

> Hi All :
>
[quoted text clipped - 36 lines]
>
> Thanks
Tom - 28 Oct 2004 06:05 GMT
Is that mean of Add Reference in parent project :

Fox example

ProjectParent.ClassA call ProjectChild.ClassB The I must add reference
(ProjectChild) in ProjectParent

However, If I don't add reference . Just like to use createobject)_ while I
don't like add reference.  How can I do these ?

> If you have a class in a separate project, make sure the start up project has
> a reference to that project in the references section of the solution tree
[quoted text clipped - 67 lines]
> >
> > Thanks
Tom - 28 Oct 2004 07:17 GMT
Is that mean of Add Reference in parent project :

Fox example

ProjectParent.ClassA call ProjectChild.ClassB The I must add reference
(ProjectChild) in ProjectParent

However, If I don't add reference . Just like to use createobject)_ while I
don't like add reference.  How can I do these ?

"Charlie" <Charlie@discussions.microsoft.com> ?b?l??
news:D14F7CD7-CD3C-482B-9DA8-90828D2E036B@microsoft.com ?????g...
> If you have a class in a separate project, make sure the start up project
has
> a reference to that project in the references section of the solution tree
> view.
[quoted text clipped - 34 lines]
> > In my testing, I create 2 .net project
> > One is MyApp (Type is windows application) with one button name
"Button1"
> > The another one is "prj01" (Type is Class libary) with one public Class
name
> > "dbLib"
> >
[quoted text clipped - 29 lines]
> >
> > Thanks
Charlie - 28 Oct 2004 07:27 GMT
Yes.  In the Start Up Project, the one that contains the forms, go to View,
Solution Explorer.  If your Class Project is not shown under References,
right click References and go to the Projects Tab, and double click the Class
Project and click OK.  Then from your Start Up Project, just use the name of
the Class Project + dot to get to the classes in the Class Project.

When you are working on the project, set Build>>Configuration Manager to
Debug for both projects.  For deployment, set the projects to Release.  The
compiled files:  the .exe (Start Up Project), and the .dll (Class Project)
will be in the bin folder of the Start Up Project folder.  You can deploy the
project to any computer that has the dot net runtime files just by copying
the files to a folder on that computer.

> Hi All :
>
[quoted text clipped - 36 lines]
>
> Thanks
Tom - 28 Oct 2004 07:46 GMT
Ok Thank :

However How to do it as dynamic ?
I mean , the reference only create on runtime , rather than Predefine.

In VB6 , dynamic add reference  method is using createobject(string) so I
can dynamic add reference to object.
However, in .Net If I need to dynamic add refernece to another .Net Project
during runtime (and not need recompile) . How can I do ?

Thanks very much

"Charlie" <Charlie@discussions.microsoft.com> ?b?l??
news:E17EFF4B-064A-4F79-80CC-04C25C471ECD@microsoft.com ?????g...
> Yes.  In the Start Up Project, the one that contains the forms, go to
View,
> Solution Explorer.  If your Class Project is not shown under References,
> right click References and go to the Projects Tab, and double click the
Class
> Project and click OK.  Then from your Start Up Project, just use the name
of
> the Class Project + dot to get to the classes in the Class Project.
>
> When you are working on the project, set Build>>Configuration Manager to
> Debug for both projects.  For deployment, set the projects to Release.
The
> compiled files:  the .exe (Start Up Project), and the .dll (Class Project)
> will be in the bin folder of the Start Up Project folder.  You can deploy
the
> project to any computer that has the dot net runtime files just by copying
> the files to a folder on that computer.
[quoted text clipped - 7 lines]
> > In my testing, I create 2 .net project
> > One is MyApp (Type is windows application) with one button name
"Button1"
> > The another one is "prj01" (Type is Class libary) with one public Class
name
> > "dbLib"
> >
[quoted text clipped - 29 lines]
> >
> > Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.