d是个6×6的二维数组,textboxs[n]含6个元素的一维数组,n=6
for (int i = 0; i< 6; i++)
{
for (int j = 0; j < 6; j++)
{
s1 = d[i, j];
p1 = s1.Split(',');
if (p1[4] != "0")
{
textboxs[n].Text = p1[2];
n++;
if (n > 6)
continue;
}
为什么n会运行到6呢?还有运行到n=6时说出界了呢?
for (int i = 0; i< 6; i++)
{
for (int j = 0; j < 6; j++)
{
s1 = d[i, j];
p1 = s1.Split(',');
if (p1[4] != "0")
{
textboxs[n].Text = p1[2];
n++;
if (n > 6)
continue;
}
为什么n会运行到6呢?还有运行到n=6时说出界了呢?
不是只有0-5吗?
{
for (int j = 0; j < 5; j++)
{
s1 = d[i, j];
p1 = s1.Split(',');
if (p1[4] != "0")
{
textboxs[n].Text = p1[2];
n++;
if (n > 5)
continue;
}
continue;
改为break;
{
textboxs[6].Text = p1[2];
n++;
if (n > 5)
continue;
}
超界了...呵...不知道是不是分析正确哦.
{
for (int j = 0; j < 6; j++)
{
s1 = d[i, j];
p1 = s1.Split(',');
if (p1[4] != "0")
{
textboxs[n].Text = p1[2];
n++;
if (n >= 6)
break; //跳出内层循环
}
}
if(n >= 6)
break;//跳出外层循环
}
for (int i = 0; i < 6 && n < 6; i++)
{
for (int j = 0; j < 6 && n < 6; j++)
{
s1 = d[i, j];
p1 = s1.Split(',');
if (p1[4] != "0")
{
textboxs[n++].Text = p1[2];
}
}
}
检查下你的d[i, j]里面的内容,是不是循环重复的,调试下。
就是textboxs[0]~textboxs[5]把代码都贴出来看看
{
for (int j = 0; j < 6; j++)
{
if (n > 6)
break;
s1 = d[i, j];
p1 = s1.Split(',');
if (p1[4] != "0")
{
textboxs[n].Text = p1[2];
n++; }
}
{"stage2,35,step1,50.0,15","stage2,35,step2,55.0,15","stage2,35,step3,72.0,30","stage2,35,step4,11,30","stage2,0,step5,0,0","stage2,0,step6,0,0"},
{"stage3,1,step1,72.0,420","stage3,1,step2,4.0,1","stage3,0,step3,0,0","stage3,0,step4,0,0","stage3,0,step5,0,0","stage3,0,step6,0,0"},
{"stage4,2,step1,10,4","stage4,2,step2,0,5","stage4,0,step3,0,0","stage4,0,step4,0,0","stge4,0,step5,0,0","stage4,0,step6,0,0"},
{"stage5,1,step1,10,11","stage5,1,step2,20,52","stage5,1,step3,0,0","stage5,1,step4,0,0","stage5,0,step5,0,0","stage5,0,step6,0,0"},
{"stage6,0,step1,0,0","stage6,0,step2,0,0","stage6,0,step3,0,0","stage6,0,step4,0,0","stage6,0,step5,0,0","stage6,0,step6,0,0"}
};
stages = new Label[] { stage1, stage2, stage3, stage4, stage5, stage6 };
cyclebts = new Button[] { cyclebt1, cyclebt2, cyclebt3, cyclebt4, cyclebt5, cyclebt6 };
temps = new Label[] { temp1, temp2, temp3, temp4, temp5, temp6 };
times = new Label[] { time1, time2, time3, time4, time5, time6 };
stepbts = new Button[] { stepbt1, stepbt2, stepbt3, stepbt4, stepbt5, stepbt6 };
for (int i2 = 0; i2 < 6 &&n<6; i++)
{
for (int j = 0; j < 6 && n < 6; j++)
{
s1 = data[i2, j];
p1 = s1.Split(',');
if (p1[4] != "0")//当step的时间不为零
{
//step[n] = p1[2];
stepbts[n].Text = p1[2];
temps[n].Text = p1[3];
times[n].Text = p1[4];
n++;
}
其实最好下标都变成I,J之类的,这样我就能再进一步操作了,呵呵
{
for (int j = 0; j < 6 && n < 6; j++)
{
s1 = data[i2, j];
p1 = s1.Split(',');
if (p1[4] != "0")//当step的时间不为零
{
//step[n] = p1[2];
stepbts[n].Text = p1[2];
temps[n].Text = p1[3];
times[n].Text = p1[4];
n++;
}
for (int i2 = 0; i2 < 6 &&n <6; i++)
==> for (int i2 = 0; i2 < 6 &&n <6; i2++)PS: n在哪里申明并初始化的?