0

I tried to split a String into a parts array and combine them at the end into a result String. But while I tested a little bit, I get a message.

By pressing convert_click:

"NullRefenceException was unhandeled"

Object reference not set to an instance of an object.

Here the main code:

    public string []parts { get; set; }
    public string inputStr { get; set; }

    private void inputText_TextChanged(object sender, EventArgs e)
    {
        String inputStr = inputText.ToString(); 
        //example 
        //inputStr = "984, fenceshit2, 0, 1994.56025813, -1592.16428141, 16.105, 0.653280779782, 0.270598520636, 0.653281646552, 0.270598879665, -1";
    }

    private void convert_Click(object sender, EventArgs e)
    {
        String creObj = "CreateObject(";
        String result;
        String[] parts = inputStr.Split(new char[]  { ',' });

        result = creObj +
                 parts[0] + "," +
                 parts[2] + "," +
                 parts[3] + "," +
                 //...up to "parts[10"
                 ");";
        outputText.Text = result; 
        //output(should be in this case): 
        //"CreateObject(984,    1994.56025813,  -1592.16428141,  16.105, 0.653280779782,  0.270598520636,  0.653281646552, 0.270598879665, -1);"
    }

    //If I need to creat a code line in the main Designer.cs, please let me know.

I just want to split a String and combine them in the end into 1 string and send this into a text box.

If someone wants the sourcecode, pm me.

2
  • What does Console.WriteLine(inputStr) output? Commented Jun 19, 2013 at 17:49
  • If you creat a console program and this line is reached, it's writing a line with the value of inputStr. Commented Jun 19, 2013 at 18:05

2 Answers 2

1

Because you are assigning inputText.toString() to local inputStr. Inside function inputText_TextChanged, just write

inputStr = inputText.Text;
Sign up to request clarification or add additional context in comments.

10 Comments

If I do this I got new problems. Non-invocable member 'System.Windows.Forms.Control.Text' cannot be used like a method.
I was guessing inputText is TextBox control. Can I know what is the inputText control is?
What you do you mean "control"?
I mean what type of GUI element is inputText box is? Is it TextBox, ComboBox, ListBox, Form or ... ?
@Knolle Did you write in your code inputStr = inputText.Text(); or inputStr = inputText.Text;?
|
0

You are declaring a local copy of input string, when you really want to be assigning to the public one.

Instead of

String inputStr = inputText.ToString(); 

Just do this:

inputStr = inputText.ToString(); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.