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 3 2959
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
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" <Ch*****@discussions.microsoft.com> ¦b¶l¥ó
news:D1**********************************@microsof t.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.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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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,...
|
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 =...
|
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 =...
|
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...
|
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.....
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
|
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
| |