0

I am having trouble converting the text from a TextBox to Double. In Win Forms it was fairy simple to convert it using the ToDouble() method, however now in WPF I am having issues with this.

First of all in the Main Window I have an int declared to help Id-ing other controls, this int is incremented only when pressing a button in order to add extra controls. Also I have a double[] declared to pass information from textboxes.

This is the int and double declaration:

public partial class MainWindow : Window
    {
        int i = 0;
        double[] Fi;

Now in the button pressed method I am trying to pass the information to the array from the textbox:

Fi[i] = double.Parse(textBox15.Text);
            MessageBox.Show("" + Fi[i]);

This is the error message I get when debugging the code:

An unhandled exception of type 'System.NullReferenceException' occurred in WpfApplication2.exe

Additional information: Object reference not set to an instance of an object.

The textbox is not null since I am inputing value to it from the keyboard, in this stage i = 0. Any advise on this matter? It is the 3rd attempt to convert, I have also user so far:

Fi[i] = Convert.ToDouble(textBox15.Text);

also giving the same error.

Bogdan U
  • 135
  • 2
  • 13

2 Answers2

0

You have to create a new array... for example:

double[] fi = new double[10];
Peter Schneider
  • 2,578
  • 1
  • 12
  • 16
0

Init the Fi array first:

double [] Fi = new double [3];

And have a look at this : https://msdn.microsoft.com/en-us/library/9b9dty7d.aspx

lboshuizen
  • 2,636
  • 15
  • 20