PC Review


Reply
Thread Tools Rate Thread

About Creating Objects Dynamically

 
 
Tom
Guest
Posts: n/a
 
      28th Oct 2004
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2hhcmxpZQ==?=
Guest
Posts: n/a
 
      28th Oct 2004
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


"Tom" wrote:

> 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
>
>
>

 
Reply With Quote
 
Tom
Guest
Posts: n/a
 
      28th Oct 2004
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" <(E-Mail Removed)> ¦b¶l¥ó
news14F7CD7-CD3C-482B-9DA8-(E-Mail Removed) ¤¤¼¶¼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.
>
> '******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
>
>
> "Tom" wrote:
>
> > 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
> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?Q2hhcmxpZQ==?=
Guest
Posts: n/a
 
      28th Oct 2004
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.


"Tom" wrote:

> 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
>
>
>

 
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
Creating objects dynamically Raj Microsoft C# .NET 2 29th Oct 2009 03:21 PM
About Creating Objects Dynamically Tom Microsoft VB .NET 0 29th Oct 2004 03:53 AM
RE: About Creating Objects Dynamically Tom Microsoft VB .NET 1 28th Oct 2004 02:45 PM
Re: About Creating Objects Dynamically Tom Microsoft VB .NET 0 28th Oct 2004 07:17 AM
Dynamically Creating Objects chris Microsoft VB .NET 1 26th May 2004 02:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:29 AM.