cannot display a list ?kam - c#

I want to dispaly a list on a button click.I have added a list box in .xaml file and want to add 10 text boxes in list.The following code shows errors.
private void listbutton_C(object sender, RoutedEventArgs e)
{
String str = "thumb_";
TextBox[] name = new TextBox[20];
for (int i = 1; i < 11; i++)
{
if (i == 10)
{
strPath = str + "0" + i + ".jpg";
}
else
{
strPath = str + "00" + i + ".jpg";
}
name[i].Text = strPath;
listBox1.Items.Add(name[i]);
}
ContentPanel2.Visibility = Visibility.Collapsed;
listBox1.Visibility = Visibility.Visible;
}
name[i].text=strpath show nullreferenceExceptions .Can somebody explain what is the problem?

I think you need to instantiate every textbox, you have only created the array.
for (int i = 1; i < 11; i++)
{
name[i] = new TextBox(); // insert this line
if (i == 10)
{
strPath = str + "0" + i + ".jpg";
}
else
{
strPath = str + "00" + i + ".jpg";
}
name[i].Text = strPath;
listBox1.Items.Add(name[i]);
}

Related

Break loop once expected line is found

string path = "xx\\xx.txt";
string[] memo = System.IO.File.ReadAllLines(path);
int totalLines = textBox2.Lines.Length;
string lastLine = textBox2.Lines[totalLines - 1];
for (int i = 0; i < 5; i++)
{
string a = memo[i];
if (a.Contains(lastLine))
{
textBox2.Text = (textBox2.Text + Environment.NewLine + memo[i + 1]);
}
}
Check the notepad from lines 0 to 4
if (a.Contains(lastLine))
{
textBox2.Text = (textBox2.Text + Environment.NewLine + memo[i + 1]);
}
I want to make above code run only once.
However, because there is a memo[i+1] variable i.
Under the influence of the for statement that repeats 5 times, the text 5 times is input.
How can I fix it?
Simply add a break statement
if (a.Contains(lastLine))
{
textBox2.Text = (textBox2.Text + Environment.NewLine + memo[i + 1]);
break;
}

Backgroundworker not updating ProgressBar although the DoWork loop is running [duplicate]

This question already has answers here:
Why does integer division in C# return an integer and not a float?
(8 answers)
Closed 5 years ago.
My program is supposed to allow the user to select multiple text files, compile the contents into a single textfile and then export it into an Excel file. I have tried using the progress bar but it only gets updated after the main loop is finished and not during it. The progress bar will jump from the min value to the max value in an instant once the loop is done. It's not slowly increasing like it suppose to. Here is my code:
public partial class Form1 : Form
{
List<string> path = new List<string>();
Workbook excelworkbook = new Workbook();
Worksheet excelworksheet = new Worksheet("First sheet");
public Form1()
{
InitializeComponent();
}
private void addfiles_Click(object sender, EventArgs e)
{
DialogResult dr = this.selectFiles.ShowDialog();
path.Clear();
if (dr == System.Windows.Forms.DialogResult.OK)
{
// Read the files
foreach (String file in selectFiles.FileNames)
{
try
{
path.Add(file);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
numFiles.Text = path.Count.ToString();
}
}
private void export_Click(object sender, EventArgs e)
{
export.Text = "Exporting...";
export.Enabled = false;
addfiles.Enabled = false;
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
try
{
backgroundWorker1.ReportProgress(15); //15% on progress bar
string[] readText = File.ReadAllLines(path[0]);
string[] readText_secondary;
string filename;
int real_length = readText.Length - 3; //create a text file that stores contents temporarily from multiple textfiles first..later will export into an excel file
using (StreamWriter streamWriter = new StreamWriter(string.Concat(Directory.GetCurrentDirectory(), "\\Temp_textfile.txt"), false)) //create temp text file
{
for (int i = 12; i <= real_length; i++)
{
backgroundWorker1.ReportProgress(((i / real_length) * 75) + 15); //suppose to update the UI here
streamWriter.Write(string.Concat(readText[i].Substring(4, 42))); //initial columns
streamWriter.Write(string.Concat(readText[i].Substring(59, 13))); //upperlimit column
if (i != 12)
{
streamWriter.Write(string.Concat(readText[i].Substring(46, 13))); //results column
}
else if (i == 12)
{
filename = Path.GetFileNameWithoutExtension(path[0]); //serial number column
streamWriter.Write(string.Concat(filename + " "));
}
for (int x = 1; x < path.Count; x++)
{
readText_secondary = File.ReadAllLines(path[x]); //secondary files
if (x != (path.Count - 1))
{
if (i != 12)
{
streamWriter.Write(string.Concat(readText_secondary[i].Substring(46, 13))); //write results
}
else if (i == 12)
{
filename = Path.GetFileNameWithoutExtension(path[x]); //write serial number header
streamWriter.Write(string.Concat(filename + " "));
}
}
else
{
if (i != 12)
{
streamWriter.WriteLine(string.Concat(readText_secondary[i].Substring(46, 13))); //write results for last column
}
else if (i == 12)
{
filename = Path.GetFileNameWithoutExtension(path[x]); //write serial number header for last column
streamWriter.WriteLine(string.Concat(filename + " "));
}
}
}
}
}
var lines = File.ReadAllLines(string.Concat(Directory.GetCurrentDirectory(), "\\Temp_textfile.txt"));
var rowcounter = 0;
foreach (var line in lines)
{
var columncounter = 0;
backgroundWorker1.ReportProgress(90);
string[] values = new string[200]; //extract the initial columns
values[0] = line.Substring(0, 10); values[1] = line.Substring(11, 8); values[2] = line.Substring(20, 8); values[3] = line.Substring(29, 12); values[4] = line.Substring(42, 12);
for (int y = 0; y < path.Count; y++)
{
values[5 + y] = line.Substring((55 + (13 * y)), 13); //extract results column
}
foreach (var value in values)
{
excelworksheet.Cells[rowcounter, columncounter] = new Cell(value); //write column by column
columncounter++;
}
rowcounter++;
}
excelworkbook.Worksheets.Add(excelworksheet); //create the excel file from object
string timedate = DateTime.Now.ToString("dd-MM-yyyy");
string excel_name = "\\ExportedData_" + timedate;
int counter = 1;
string new_path = string.Concat(Directory.GetCurrentDirectory() + excel_name + ".xls"); //this part is to prevent overwriting
while (File.Exists(new_path))
{
new_path = string.Concat(Directory.GetCurrentDirectory() + excel_name + "(" + counter + ")" + ".xls");
counter++;
}
excelworkbook.Save(new_path); //save into path
if (File.Exists(string.Concat(Directory.GetCurrentDirectory(), "\\Temp_textfile.txt"))) //delete temporary text file
{
File.Delete(string.Concat(Directory.GetCurrentDirectory(), "\\Temp_textfile.txt"));
}
backgroundWorker1.ReportProgress(100);
}
catch (Exception ex)
{
MessageBox.Show("Error occurred!\n" + ex, "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Warning);
addfiles.Text = "Add Files";
export.Text = "Export!";
numFiles.Clear();
addfiles.Enabled = true;
export.Enabled = true;
}
}
private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
MessageBox.Show("Done exporting!", "Notification Window", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
addfiles.Text = "Add Files";
export.Text = "Export!";
numFiles.Clear();
addfiles.Enabled = true;
export.Enabled = true;
}
}
I cant seem to what's the problem here. Can someone point me to the right direction?
backgroundWorker1.ReportProgress(((i / real_length) * 75) + 15);
The issue is that (i / real_length) returns 0 since you are using integer division.
Instead you need to do:
backgroundWorker1.ReportProgress((int)((((double)i / real_length) * 75) + 15));
or:
backgroundWorker1.ReportProgress(i * 75 / real_length + 15);
I would recommend the former.

How to show the number of files moved and moved file name in a dialog box

I have a move function which moves the files from one folder to another folder..
I am wondering how can i show the total numbers of files moved and moved filenames in a dialog box. or any idea..!!!!
Here the problem is, Once i press Move all the files moving, if at all there are some duplicate files it shows error msg in my grid view.. rest files starts keeps moving. SO i need a method once all files are moved.. i need to show a dialog box with total number of files moved and filenames moved in a dialog box.. is that possible.. or any idea.. Please post it..
I really appriciate that..
My codes:
private void button3_Click(object sender, EventArgs e)
{
update = false;
this.Enabled = false;
backgroundWorker2.RunWorkerAsync();
move();
backgroundWorker2.CancelAsync();
System.Threading.Thread.Sleep(500);
this.Enabled = true;
update = true;
}
public void move()
{
update = false;
string archieve_path = ini.ReadValue("Location", "Archive");
string release_path = ini.ReadValue("Location", "Release");
string draft_path = ini.ReadValue("Location", "Draft");
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if ((!String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString()) && String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Release Path"].Value.ToString())) &&
(dataGridView1.Rows[i].Cells[0].Value != null && (bool)dataGridView1.Rows[i].Cells[0].Value))
{
string draftpath = dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString();
string relasepath = dataGridView1.Rows[i].Cells["Release Path"].Value.ToString();
string archievepath = dataGridView1.Rows[i].Cells["Archive"].Value.ToString();
string draftname = System.IO.Path.GetFileName(draftpath);
if (relasepath != string.Empty && draftname.Equals(Path.GetFileName(relasepath), StringComparison.OrdinalIgnoreCase))
{
dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Release: " + draftname + "";
dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
continue;
}
if (archievepath != string.Empty && draftname.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
{
dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + draftname + "";
dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
continue;
}
string newpath = System.IO.Path.Combine(release_path, draftname);
System.IO.File.Move(draftpath, newpath);
dataGridView1.Rows[i].Cells["Release Path"].Value = newpath;
dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
dataGridView1.Rows[i].Cells[0].Value = false; //Checkbox
}
if ((!String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString())
&& !String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Release Path"].Value.ToString())) &&
(dataGridView1.Rows[i].Cells[0].Value != null && (bool)dataGridView1.Rows[i].Cells[0].Value))
{
string draftPath = dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString();
string releasepath = dataGridView1.Rows[i].Cells["Release Path"].Value.ToString();
string archievepath = dataGridView1.Rows[i].Cells["Archive"].Value.ToString();
string draftname = System.IO.Path.GetFileName(draftPath);
string archievename = System.IO.Path.GetFileName(archievepath);
string releasename = System.IO.Path.GetFileName(releasepath);
if (archievepath != string.Empty && draftname.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
{
dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + draftname + "";
dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
continue;
}
if (releasepath != string.Empty && draftname.Equals(Path.GetFileName(releasepath), StringComparison.OrdinalIgnoreCase))
{
dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Release: " + draftname + "";
dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
continue;
}
if (archievepath != string.Empty && releasename.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
{
dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + releasename + "";
dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
continue;
}
string fName1 = System.IO.Path.GetFileNameWithoutExtension(draftPath);
string fName2 = System.IO.Path.GetFileNameWithoutExtension(releasepath);
string fName3 = System.IO.Path.GetFileNameWithoutExtension(archievepath);
var f1 = GetValue(fName1.ToCharArray()[fName1.Length - 2]) * 16 + GetValue(fName1.ToCharArray()[fName1.Length - 1]);
var f2 = GetValue(fName2.ToCharArray()[fName2.Length - 2]) * 16 + GetValue(fName2.ToCharArray()[fName2.Length - 1]);
// var f3 = GetValue(fName3.ToCharArray()[fName3.Length - 2]) * 16 + GetValue(fName3.ToCharArray()[fName3.Length - 1]);
if (f1 > f2)//till here
{
//moves from realse to archieve
string newpath = System.IO.Path.Combine(archieve_path, releasename); //draft name + archieve
System.IO.File.Move(releasepath, newpath);
dataGridView1.Rows[i].Cells["Release Path"].Value = string.Empty;
}
if (f1 < f2)
{
//moves draft to archieve
string newpath = System.IO.Path.Combine(archieve_path, draftname);
System.IO.File.Move(draftPath, newpath);
dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
return;
}
string newpath1 = System.IO.Path.Combine(release_path, draftname);
System.IO.File.Move(draftPath, newpath1);
dataGridView1.Rows[i].Cells["Release Path"].Value = newpath1;
dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
dataGridView1.Rows[i].Cells[0].Value = false; //Checkbox
}
}
update = true;
}
Added code:
StringBuilder sbBody = new StringBuilder();
List<string> lstFiles = new List<string>();
foreach (string file in Directory.GetFiles(newpath, "*.txt"))
{
// msg.Attachments.Add(new System.Net.Mail.Attachment(file));
lstFiles.Add(file);
}
I would have thought this was a dupe, but apparently it isn't. Anyway, here's the outline.
Add a ProgressChanged event to backgroundWorker2, and have it run move() as well (which will require rewriting the function to split out all the code that updates the UI for errors and such-like into ProgressChanged delegate calls). In the event handler, update the UI with the newly-modified count and filename data from the parameters.

c# acces array outside for loop

i was wondering how to acces a array outside a forloop.
string[] lines = File.ReadAllLines("Customers/" + listBox1.SelectedItem.ToString() + "/" + listBox1.SelectedItem.ToString() + ".txt");
for (int i = 0; i < 4; i++)
{
string[] linesSplitted = lines[i].Split(':');
}
TextboxName.Text = linesSplitted[0];
TextboxAddress.Text = linesSplitted[1];
TextboxZip.Text = linesSplitted[2];
TextboxTel.Text = linesSplitted[3];
TextboxEmail.Text = linesSplitted[4];
at this point, it does not recognize linesSplitted.
From your comment on another answer, I guess you want this:
string[] linesSplitted = new string[5];
for (int i = 0; i < 5; i++)
{
linesSplitted[i] = lines[i].Split(':')[1];
}
If this is not what you want, give us an example of the contents of the text file.
Declare the array outside of the loop. E.g.
string[] lines = File.ReadAllLines("Customers/" + listBox1.SelectedItem.ToString() + "/" + listBox1.SelectedItem.ToString() + ".txt");
string[] linesSplitted;
for (int i = 0; i < 4; i++)
{
linesSplitted = lines[i].Split(':');
}
TextboxName.Text = linesSplitted[0];
TextboxAddress.Text = linesSplitted[1];
TextboxZip.Text = linesSplitted[2];
TextboxTel.Text = linesSplitted[3];
TextboxEmail.Text = linesSplitted[4];
string[] lines = File.ReadAllLines("Customers/" + listBox1.SelectedItem.ToString() + "/" + listBox1.SelectedItem.ToString() + ".txt");
string[] linesSplitted;
for (int i = 0; i < 4; i++)
{
linesSplitted = lines[i].Split(':');
}
TextboxName.Text = linesSplitted[0];
TextboxAddress.Text = linesSplitted[1];
TextboxZip.Text = linesSplitted[2];
TextboxTel.Text = linesSplitted[3];
TextboxEmail.Text = linesSplitted[4];
I'm not to sure about what you're trying to achieve there...
string[] lines = File.ReadAllLines("Customers/" + listBox1.SelectedItem.ToString() + "/" + listBox1.SelectedItem.ToString() + ".txt");
List<string[]> data = new List<string[]>();
for (int i = 0; i < 4; i++)
{
data.Add(lines[i].Split(':'));
}
//Retrive array from list and value from array and set to text box
TextboxName.Text = linesSplitted[0];
TextboxAddress.Text = linesSplitted[1];
TextboxZip.Text = linesSplitted[2];
TextboxTel.Text = linesSplitted[3];
TextboxEmail.Text = linesSplitted[4];

Need help in finding the cause of Index out of range exception message

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
I have the class WireObjectAnimation:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using DannyGeneral;
namespace AnimationEditor
{
class WireObjectAnimation
{
private List<WireObjectCoordinates> wocl = new List<WireObjectCoordinates>();
private WireObject wo1 = null;
string name;
int ndx;
public WireObjectAnimation(string name,WireObject wo)
{
this.name = name;
wo1 = wo;
WireObjectCoordinates woc;
woc = new WireObjectCoordinates(wo.woc);
wocl.Add(woc);
ndx = 0;
}
public void Save(string path , string fileName , PictureBox pb)
{
int framesNumberX = 0;
int framesNumberY = 0;
string fn;
string t = Path.GetFileNameWithoutExtension(this.name);
if (File.Exists(path + "\\" + "DATABASE" + "\\" + fileName + "\\" + t + ".txt"))
{
try
{
string f = Path.Combine(path + "\\" + "DATABASE" + "\\" + t + "\\" + fileName);
File.Delete(f);
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not delete file from disk. Original error: " + ex.Message);
}
fn = path + "\\" + "DATABASE" + "\\" + t + "\\" + fileName;
}
else
{
fn = path + "\\" + "DATABASE" + "\\" + fileName + "\\" + this.name + ".txt";
}
OptionsFile setting_file = new OptionsFile(fn);
setting_file.SetKey("File Name", fn);
setting_file.SetKey("Object Name", fileName);
setting_file.SetKey("Animation Name", this.name);
setting_file.SetKey("picturebox.Width", pb.Width.ToString());
setting_file.SetKey("picturebox.Height", pb.Height.ToString());
string[] xFrames = new string[wocl.Count];
string[] yFrames = new string[wocl.Count];
string X="";
string Y="";
for (int i = 0; i < wocl.Count; i++)
{
X = string.Format("Frame_X_{0} ", i + 1);
Y = string.Format("Frame_Y_{0} ", i + 1);
framesNumberX ++;
framesNumberY ++;
for (int j = 0; j < wocl[i].Point_X.Count; j++)
{
xFrames[i] += string.Format("{0},", wocl[i].Point_X[j]);
yFrames[i] += string.Format("{0},", wocl[i].Point_Y[j]);
}
string tt = xFrames[i].Trim(",".ToCharArray());
string yy = yFrames[i].Trim(",".ToCharArray());
setting_file.SetKey(X, tt);
setting_file.SetKey(Y, yy);
}
int resultX = framesNumberX / 2;
int resultY = framesNumberY / 2;
setting_file.SetKey("Number Of Frames X", resultX.ToString());
setting_file.SetKey("Number Of Frames Y", resultY.ToString());
}
public void Load(string path,string fileName)
{
int numberofframesX = 0;
int numberofframesY = 0;
string framesX = "";
string framesY = "";
string X = "";
string Y = "";
string t = path + "\\" + fileName;
OptionsFile setting_file = new OptionsFile(t);
string XX = setting_file.GetKey("Number Of Frames X");
string YY = setting_file.GetKey("Number Of Frames Y");
numberofframesX = Convert.ToInt32(XX);
numberofframesY = Convert.ToInt32(YY);
for (int i = 1; i < numberofframesX ; i++)
{
X = string.Format("Frame_X_{0} ", i);
framesX = setting_file.GetKey(X);
List<string> floatStrings = new List<string>(framesX.Split(new char[] { ',' }));
List<float> test = floatStrings.Select(tempStr => (float)Convert.ToDouble(tempStr)).ToList();
wo1.woc.Point_X = test;
}
for (int i = 1; i < numberofframesY; i++)
{
Y = string.Format("Frame_Y_{0} ", i);
framesY = setting_file.GetKey(Y);
List<string> floatStrings = new List<string>(framesY.Split(new char[] { ',' }));
List<float> test = floatStrings.Select(tempStr => (float)Convert.ToDouble(tempStr)).ToList();
wo1.woc.Point_Y = test;
}
}
public void SetFrame(int frameNumber, WireObjectCoordinates woc)
{
wocl[frameNumber].Set(woc);
}
public WireObjectCoordinates GetFrame(int frameNumber)
{
if (frameNumber > wocl.Count)
{
throw new Exception("not allowed!");
}
if (frameNumber == wocl.Count)
{
WireObjectCoordinates woc;
woc = new WireObjectCoordinates(wocl[wocl.Count - 1]);
wocl.Add(woc);
return woc;
}
else
{
return wocl[frameNumber];
}
}
}
}
Now when im doing loading the Load function i see the points its loading it good.
But then im trying to move the trackBar bar scroll to the right and then im getting the exception. Now thisl ine: wo1.woc.Point_X = test; the woc have 4 indexs and in each index Point_X and Point_Y are filled with numbers in each index.
In this class i have the functions SetFrame and GetFrame and im using GetFrame in Form1 scroll event of the trackBar:
private void trackBar1_Scroll(object sender, EventArgs e)
{
currentFrameIndex = trackBar1.Value;
textBox1.Text = "Frame Number : " + trackBar1.Value;
wireObject1.woc.Set(wireObjectAnimation1.GetFrame(currentFrameIndex));
LoadPictureAt(trackBar1.Value, sender);
button1.Enabled = false;
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
button8.Enabled = false;
SaveFormPicutreBoxToBitMapIncludingDrawings();
return;
}
Now when im moving the trackBar once to the right it should paint the next set of numbers from the Point_X and Point_Y instead its going to the WireObjectCoordinates class and throw there the exception:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace AnimationEditor
{
class WireObjectCoordinates
{
public List<float> Point_X = new List<float>();
public List<float> Point_Y = new List<float>();
public WireObjectCoordinates()
{
}
public WireObjectCoordinates(WireObjectCoordinates w)
{
Point_X.AddRange(w.Point_X);
Point_Y.AddRange(w.Point_Y);
}
public void Set(WireObjectCoordinates w)
{
for (int i = 0; i < Point_X.Count; i++)
{
Point_X[i] = w.Point_X[i];
Point_Y[i] = w.Point_Y[i];
}
}
}
}
The exception is on the line: Point_X[i] = w.Point_X[i];
Point_X[i] contain now 4 indexs from [0] to [3] each index contain a number like 332.0 333.0 334.0 335.0
And w.Point_X[i] contain now only one index [0] and this index have the number 332.0
i just dont understand why the exception is on this line.
The idea is that when im moving the trackBar to the right it should draw the next coordinates from the wo1.woc.Point_Y and wo1.woc.Point_X but i guess i did something wrong in the Load function ? Im not sure why its throwing the exception and its only when im moving the trackBar to the right once.
How do you expect your for loop to work? The loop variable i goes from 0 to the count of the Point_X list of this instance. But if the other instance w has a Point_X list of a lower count, or if the Point_Y list of this or the Point_Y list of w has, it will fail.
If you realize that Point_X.Count is 4 and w.Point_X.Count is only 1, then when i exceeds 0, the expression w.Point_X[i] will try to read an element of the list that does not exist. That throws the excpetion "Index was out of range".
But maybe you understand that?
throw a try catch around it it technically wont fix the problem but it wont crash anymore and just read over the error

Categories