y = Convert.ToDouble(lstChars.ToString()); gives the following error: Input string was not in a correct format. what can I do about this? Thanks for your reply.
kelvinic
Posts
-
Reading text file problem with casting to double -
Reading text file problem with casting to doubleI've trying to read a .txt files in order to plot the data on a ZedGraph. The problem is I cannot convert the data to double. The compiler gives bunch of errors(Error 1 Cannot convert type 'string' to 'double'). The following is a piece of code that i'm having trouble with. private void BRead(GraphPane myPane) { FileStream fleReader = new FileStream("kel.txt", FileMode.Open, FileAccess.Read); StreamReader stmReader = new StreamReader(fleReader); StringBuilder lstChars = new StringBuilder(); double x = 0, y; int iChar = stmReader.Read(); lstChars.Append((char)iChar); // double[] yx = new double[lstChars.Length]; PointPairList list = new PointPairList(); while (iChar > -1) { x = x + (double)0.0002; iChar = stmReader.Read(); lstChars.Append((char)iChar); y = (double)(lstChars.ToString()); //error list.Add(x, y); } this.textBox1.Text = lstChars.ToString(); stmReader.Close(); CurveItem myCurve = myPane.AddCurve("My Curve",list, Color.Red, SymbolType.Diamond); } can anyone help me please!!