I have a code that allow user to select files and get the data assign into array.
private void Load_data_Click(object sender, EventArgs e)
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "C:\\DataArray";
openFileDialog1.Filter = "txt files (*.txt)|*.txt";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
string filename = openFileDialog1.FileName;
var lineCount = 0;
using (var reader = File.OpenText(@filename))
{
while (reader.ReadLine() != null)
{
lineCount++;
}
for(var count = 0; count < lineCount; ++count)
{
var data = reader.ReadLine().Split(',');
GlobalDataClass.dDataArray[count, 0] = double.Parse(data[0]);
GlobalDataClass.dDataArray[count, 1] = double.Parse(data[1]);
}
ShowGraphData(lineCount);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
Once assign, I call the function showgraphdata to plot zedgraph.
public void ShowGraphData(long lTotalData)
{
double[] dx = new double[lTotalData];
double[] dy = new double[lTotalData];
for (long li = 0; li < lTotalData; li++)
{
dx[li] = GlobalDataClass.dDataArray[li, 0];
dy[li] = GlobalDataClass.dDataArray[li, 1];
}
zedGraphControlStickiness.GraphPane.CurveList.Clear();
GraphPane StickinessPane = zedGraphControlStickiness.GraphPane;
// PointPairList holds the data for plotting, X and Y arrays
PointPairList spl1 = new PointPairList(dx, dy);
// Add cruves to myPane object
LineItem ProductionCurve = StickinessPane.AddCurve("Insertion Force", spl1, Color.Blue, SymbolType.None);
ProductionCurve.Line.Width = 2.0F;
zedGraphControlStickiness.AxisChange();
zedGraphControlStickiness.Invalidate();
zedGraphControlStickiness.Refresh();
GlobalDataClass.iTotalReadingPoint = lTotalData;
}
but when i execute this code, i got this error: "object reference not set to an instance of an object"
Can someone advise me wheres my mistake?tQ