Need Some Help - Index Outside Bounds of Array

Hello you wonderful people!
I am in need of your experience, expertise, and guidance once again. I have been racking my brain trying to figure out what is wrong with my code that is causing it to produce this Application Error.

Maybe one of you can assist me in finding the issue in my script.

//Label Script for Serialized Tube 0520
private void Form_AM0520SN()//AMSerialized Tube Labels
{
EpiTextBox etxtJob = (EpiTextBox)csm.GetNativeControlReference(“71c3e8b2-bf25-42ff-b952-8dab2e16107a”);
EpiTextBox etxtPartNum = (EpiTextBox)csm.GetNativeControlReference(“4b8e7b4e-33f9-4abb-9835-214475913e95”);
EpiTextBox etxtCustPartNum = (EpiTextBox)csm.GetNativeControlReference(“b642bbae-c1a2-46c0-af58-f18ddcf8f849”);
EpiTextBox etxtRev = (EpiTextBox)csm.GetNativeControlReference(“4c89e6e7-58c9-4429-8c63-7016452bea21”);
EpiTextBox etxtCustPartRev = (EpiTextBox)csm.GetNativeControlReference(“8539bf33-2f02-4628-8608-9cc1ad7d687a”);
EpiTextBox etxtPartDesc = (EpiTextBox)csm.GetNativeControlReference(“853c6e43-34b5-4550-b168-c7d1a8891532”);
EpiUltraGrid gridSerials = (EpiUltraGrid)csm.GetNativeControlReference(“fc13911b-15f9-40d5-8668-370e6c0663e6”);
EpiUltraGrid gridLabel = (EpiUltraGrid)csm.GetNativeControlReference(“cb335fb6-d957-485a-8333-0da630a2ac5f”);
EpiTextBox etxtQtyToPrint = (EpiTextBox)csm.GetNativeControlReference(“52b6eb17-2ee3-4ccf-a590-a339bc939101”);

	//get week
	CultureInfo myCI = new CultureInfo("en-US");
	Calendar myCal = myCI.Calendar;
	CalendarWeekRule myCWR = myCI.DateTimeFormat.CalendarWeekRule;
	DayOfWeek myFirstDOW = myCI.DateTimeFormat.FirstDayOfWeek;
	string curWeek = myCal.GetWeekOfYear( DateTime.Now, myCWR, myFirstDOW ).ToString("00");
	string curYY = DateTime.Now.ToString("yy");

	//clear current label rows
	gridLabel.Selected.Rows.AddRange((Infragistics.Win.UltraWinGrid.UltraGridRow[])gridLabel.Rows.All);
	gridLabel.DeleteSelectedRows(false);
	gridLabel.DisplayLayout.Bands[0].AddNew();
	gridLabel.DisplayLayout.Bands[0].AddNew();
	gridLabel.DisplayLayout.Bands[0].AddNew();
	gridLabel.DisplayLayout.Bands[0].AddNew();
	gridLabel.DisplayLayout.Bands[0].AddNew();
	gridLabel.Rows[0].Cells[0].Value = Convert.ToString(etxtCustPartNum.Value); gridLabel.Rows[0].Update();
	gridLabel.Rows[1].Cells[0].Value = Convert.ToString(etxtCustPartRev.Value); gridLabel.Rows[1].Update();
	gridLabel.Rows[2].Cells[0].Value = "900-{Wy}-{Sn}" ; gridLabel.Rows[2].Update();
	gridLabel.Rows[3].Cells[0].Value = Convert.ToString(etxtJob.Value); gridLabel.Rows[3].Update();
	gridLabel.Rows[4].Update();
	//gridLabel.Rows[3].Cells[0].Value = "{SN}"; gridLabel.Rows[3].Update();
	//gridLabel.Rows[4].Cells[0].Value = Convert.ToString(etxtJob.Value); gridLabel.Rows[4].Update();		

	this.epitbWWWYY.Value = curWeek+curYY;
	this.epitbWWWYY.Visible = true;

}	

Thank you ahead of time for anyone who takes a few minutes to look at this. You rock!

P.S. Please do not judge my script to harshly, I am not a Computer Programmer and I am just learning how to do this by following what already exists in the application.

Maybe try commenting that out and see what happens? Not sure if that’s the problem, but it looks a little strange trying to update an empty row.

Also, maybe try to comment out the extra.

I’m definitely no expert, so none of it may work.

Thank you for the suggestion John Kane, I really appreciate it!! I just tested that, unfortunately that did not resolve the issue. Error code still appears. :confused:

Does the grid you are updating have 5 rows in it and does each row have a cell in it? If you have a supported version of Visual Studio, you can open the form and check the box to Debug in Visual Studio (to set break points and look at values). If you don’t, try commenting out the lines from the bottom up to determine where the error is happening

I figured it out. I have a Private Void that is checking the lines in the grid, which it is set to check 7 lines. In the label private void, it only has 4 lines so it is throwing a warning that is is out of array. It can’t check 7 when there are only four.

1 Like