convert string to double now working?
Hy everybody! I'm new here and I'd like to ask a question right away. So,
I'd like to convert a string to a double. I konw, it has been asked
before, but let me finish it! :) So I read the string in from a usb
port(arduino experiment), and I'd like to add that value to a list of
doubles. The values are comming in continously. The problem is, when I try
to convert the string to double it gives an error message that says:"The
format of the incomming character chain is wrong." or something like this.
I get this error message with both the parse and convert command. What
should I do? Here's the part of the code that supposed to do the job:
namespace voltmeres{
public partial class Form1 : Form
{
List<double> lista = new List<double>();
int i;
double f;
string POT;
public Form1()
{
InitializeComponent();
serialPort1.PortName = "COM5";
serialPort1.BaudRate = 9600;
lista.Capacity = 100;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
POT =serialPort1.ReadExisting();
textBox1.Text = POT.ToString();
}
f = Convert.ToDouble(textBox1.Text);
lista.Add(f);
i++;
if (i == lista.Capacity)
{
lista.Capacity=lista.Capacity + 100;
}
}
Thank you in advance!
No comments:
Post a Comment