I'm having "Input string was not in a correct format." error from this code
rainTb.Text = " " + int.Parse(parsed[0]) * 100 / 1023;
There's no error in my code. Except for the error above. I've made a calculation to extract the analogue value (above calculation) from Arduino hardware via serial communication (cable). Arduino works fine though. Everything was fine though until this error shows up... Why? cries
p/s : I've gone through many solutions but still.. So here I am now. Sorry for my English
private void ProcessCOMRx(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(COMRx))
{
systemTb.Text = "Processing Data...";
systemTb.BackColor = System.Drawing.Color.Lime;
string [] parsed = COMRx.Split(',');
int curveNo;
if (parsed.Count() > zedAll.GraphPane.CurveList.Count())
curveNo = zedAll.GraphPane.CurveList.Count();
else
curveNo = parsed.Count();
for (int k = 0; k < curveNo; k++)
{
for (int j = zedAll.GraphPane.CurveList[k].NPts - 1; j > 0; j--)
{
zedAll.GraphPane.CurveList[k].Points[j].Y = zedAll.GraphPane.CurveList[k].Points[j - 1].Y;
}
double temp = 0;
try
{
temp = double.Parse(parsed[k]);
}
catch
{
systemTb.Text = "Parse Error";
systemTb.BackColor = System.Drawing.Color.Red;
}
rainTb.Text = "" + int.Parse(parsed[0]) * 100 / 1023;
phTb.Text = "" + (3.5 + int.Parse(parsed[1]) * 4.5 / 1023);
moistTb.Text = "" + int.Parse(parsed[2]) * 100 / 1023;
tempTb.Text = "" + int.Parse(parsed[3]) * 100 / 1023;
zedAll.GraphPane.CurveList[k].Points[0].X = 0;
zedAll.GraphPane.CurveList[k].Points[0].Y = temp;
}
}
else
{
this.BeginInvoke(new EventHandler(processPumpStates));
}
}