I am reading line by line from a textfile and i will populate 100 textbox from the textfile ( 10x10 line ) there is 10 comma in each line and there is 10 line in the textfile so i am trying to read the value from textfile . But however it shows Index was out of bounds , any help?
string[] fileData = File.ReadAllLines(@"C:\Users\omgjyan\Desktop\OneOrganizer\OneOrganizer\WordPuzzle\educational.txt");
string[] lineValues;
int row = 0;
int col;
string[][] rowcol = new string[fileData.Length][];
foreach (string line in fileData)
{
lineValues = line.Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries);
rowcol[row] = new string[lineValues.Length];
col = 0;
foreach (string value in lineValues)
{
rowcol[row][col] = value;
col++;
}
row++;
}
for (int i = 0; i < rowcol.GetLength(0); i++)
{
for (int j = 0; j < rowcol[i].GetLength(0); j++)
{
TextBox tbox = new TextBox();
int iadd = i + 1;
int iminus = i - 1;
int jadd = i + 1;
int jminus = i - 1;
var self = rowcol[i][j];
var top = rowcol[iminus][j];
var bottom = rowcol[iadd][j];
var left = rowcol[i][jminus];
var right = rowcol[i][jadd];
if ((!String.IsNullOrEmpty(self) && String.IsNullOrEmpty(top) && String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && !String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(top) && !String.IsNullOrEmpty(right) && String.IsNullOrEmpty(bottom) && !String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(top) && !String.IsNullOrEmpty(right) && String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && String.IsNullOrEmpty(top) && !String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(top) && !String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(top) && String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && !String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && String.IsNullOrEmpty(top) && !String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && !String.IsNullOrEmpty(left))
)
{
tbox.Text = "*";
}
wrapPanel1.Children.Add(tbox);
}
}
I got the error saying index was out of bounds . Could it be the +1 and -1? how do i solve that
error :