Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Passing textbox value into instance

Passing textbox value into instance

Scheduled Pinned Locked Moved Windows Forms
help
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 4467008
    wrote on last edited by
    #1

    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

    H L 2 Replies Last reply
    0
    • U User 4467008

      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

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      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 a Form. The second line then tries to change frm1 into whatever you have in TextBox1.Text, unfortunately whatever you have there cannot be found so frm1 is set to null 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 in acode.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 your acode.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.”

      1 Reply Last reply
      0
      • U User 4467008

        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

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

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


        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups