473,588 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

About Creating Objects Dynamically

Tom
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim oCar As Object
Dim ty As Type = Type.GetType("p rj01.dbLib")
oCar = Activator.Creat eInstance(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
Nov 21 '05 #1
3 2980
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.GetThisMessa ge("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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim oCar As Object
Dim ty As Type = Type.GetType("p rj01.dbLib")
oCar = Activator.Creat eInstance(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

Nov 21 '05 #2
Tom
Is that mean of Add Reference in parent project :

Fox example

ProjectParent.C lassA call ProjectChild.Cl assB 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" <Ch*****@discus sions.microsoft .com> bl
news:D1******** *************** ***********@mic rosoft.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.

'******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.GetThisMessa ge("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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim oCar As Object
Dim ty As Type = Type.GetType("p rj01.dbLib")
oCar = Activator.Creat eInstance(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

Nov 21 '05 #3
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>>Configur ation 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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim oCar As Object
Dim ty As Type = Type.GetType("p rj01.dbLib")
oCar = Activator.Creat eInstance(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

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
565
by: Bhavin | last post by:
Anybody quickly replies it, would be a great help! I try to create dynamic array of textboxes control in ASP.NET(C#). I got the following error while I tried to assign value to ID property of dynamically created textbox. (look at my code please ) Error: “ Object reference is not set to an instance of Object” totalRows – int variable which varies with number of records in SQL table
7
1576
by: Snake | last post by:
Hi guys, I have question about classes. when u create class called Test. and you define variable Test c; so does this act like( a variable c of type Test pointing to an abject )? The thing that I am confused with java where you say Test c = new Test; whre you can move this Test object around by saying "Test b" and then b = c;(so c and b points to the same object). while in c++ I think it has different meaning(like b would have different...
1
1349
by: chris | last post by:
I know I've asked this before, but I didn't really get an answer and I bet it's because I didn't explain myself very well. Here goes again. I have this code: Dim arrData(intNoOfRows, intNoOfColumns) As Object Dim intR As Integer For intC As Integer = 0 To intNoOfColumns - 1
0
310
by: Tom | last post by:
Thanks Chris : However, during run time, it show error message "File / component cannot find " during run in Dim asm As = AppDomain.CurrentDomain.Load("D:\vb7Project\dynamicCall\prj01\prj01\bin\prj0 1.dll")
2
1217
by: Tom | last post by:
Thanks Chris : However, during run time, it show error message "File / component cannot find " during run in Dim asm As = AppDomain.CurrentDomain.Load("D:\vb7Project\dynamicCall\prj01\prj01\bin\prj0 1.dll")
105
5280
by: Christoph Zwerschke | last post by:
Sometimes I find myself stumbling over Python issues which have to do with what I perceive as a lack of orthogonality. For instance, I just wanted to use the index() method on a tuple which does not work. It only works on lists and strings, for no obvious reason. Why not on all sequence types? Or, another example, the index() method has start and end parameters for lists and strings. The count() method also has start and end parameters...
161
7790
by: KraftDiner | last post by:
I was under the assumption that everything in python was a refrence... so if I code this: lst = for i in lst: if i==2: i = 4 print lst I though the contents of lst would be modified.. (After reading that
9
2303
by: kathy | last post by:
I am using std::vector in my program: func() { std::vector <CMyClass *> vpMyClass; vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new CMyClass()); vpMyClass.push_back(new CMyClass()); //???? Required ??????????????//
75
5411
by: Steven T. Hatton | last post by:
No, this is not a troll, and I am not promoting Java, C-flat, D, APL, Bash, Mathematica, SML, or LISP. A college teacher recently posted to this newsgroup regarding her observation that there has been a significant decline in the number of students opting to take courses in C++. I just want to let people know what I believe are the biggest obstacles to C++ language acquisition, and what aspects of the language make it less appealing than...
1
1565
by: krishna81m | last post by:
I am unable to create a list of objects dynamically. I run a SQL query on the database and populate objects of types that I also know aprior. I read the query as a string, run it on the database and want to be able to populate these objects of classes whose names are known to me also based on the type of the query. In this query, SomeClass is a variable. Class myClass = Class.forName("SomeClass"); Object myClassObj =...
0
7929
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8228
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8223
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5729
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5398
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3847
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.