Passing textbox value into instance
-
I have written the following code in windows --------------------------------------------- TextBox1.Text = Application.ProductName + "." + acode.Text; System.Reflection.Assembly tempAssembly = System.Reflection.Assembly.GetExecutingAssembly(); Form frm1 = new Form(); Form frm1 = (Form)tempAssembly.CreateInstance(TextBox1.Text); frm1.show(); --------------------------------------------- Here error is been generated,in frm1.show() line,object reference not set to an instance of the object.The TextBox1.Text contents are not been displayed in frm1 which is the instance of Form and getting null value Please suggest me the solution to the error above. Thanks Ramesh
-
I have written the following code in windows --------------------------------------------- TextBox1.Text = Application.ProductName + "." + acode.Text; System.Reflection.Assembly tempAssembly = System.Reflection.Assembly.GetExecutingAssembly(); Form frm1 = new Form(); Form frm1 = (Form)tempAssembly.CreateInstance(TextBox1.Text); frm1.show(); --------------------------------------------- Here error is been generated,in frm1.show() line,object reference not set to an instance of the object.The TextBox1.Text contents are not been displayed in frm1 which is the instance of Form and getting null value Please suggest me the solution to the error above. Thanks Ramesh
There is at least one obvious problem:
Form frm1 = new Form();
Form frm1 = (Form)tempAssembly.CreateInstance(TextBox1.Text);The first of these two lines sets
frm1
to be a new instance of aForm
. The second line then tries to changefrm1
into whatever you have inTextBox1.Text
, unfortunately whatever you have there cannot be found sofrm1
is set tonull
which is why you are getting the error. You probably do not need the first line. If you show an example of what might be inacode.Text
people might be better able to help you. In the interim you might want to try:Form frm1 = (Form)tempAssembly.CreateInstance(TextBox1.Text, true);
Which tells
CreateInstance
not to worry about the case of the parameter text, just in case youracode.Text
is correct except for the case.Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
I have written the following code in windows --------------------------------------------- TextBox1.Text = Application.ProductName + "." + acode.Text; System.Reflection.Assembly tempAssembly = System.Reflection.Assembly.GetExecutingAssembly(); Form frm1 = new Form(); Form frm1 = (Form)tempAssembly.CreateInstance(TextBox1.Text); frm1.show(); --------------------------------------------- Here error is been generated,in frm1.show() line,object reference not set to an instance of the object.The TextBox1.Text contents are not been displayed in frm1 which is the instance of Form and getting null value Please suggest me the solution to the error above. Thanks Ramesh
Member 4470223 wrote:
Form frm1 = new Form(); Form frm1 = ...;
that does not compile without errors, does it? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).