请问下面这段代码,为什么只能循环一次,哪里不对吗?(执行到5就报错)
Dim tb As Table = Tables("库存调整_调增table1")
Dim tb2 As Table = Tables("库存调整_调减table1")
For i As Integer = tb.Rows.Count -1 To 0 Step -1 ''遍历所有行
For i2 As Integer = tb2.Rows.Count -1 To 0 Step -1 ''遍历所有行
If i >=0 AndAlso i2 >= 0 AndAlso i = i2 AndAlso tb.Rows(i).Checked AndAlso tb2.Rows(i2).Checked AndAlso ckb.Checked = False Then '二者位置相同,且都选中,没开启
MessageBox.show(1)
If tb.Rows(i).IsNull("调增数量") = False AndAlso tb2.Rows(i2).IsNull("调减数量") = False Then '二者数量都不为空
MessageBox.show(2)
If cmb.value.Contains("901") AndAlso tb.rows(i)("编码") = tb2.rows(i2)("编码") Then '901状态调整,编码要相同
MessageBox.show(3)
Dim r3 As Row = Tables("库存").AddNew() '增加数据
r3("物料编码") = tb.rows(i)("编码")
r3("移动单元") = tb.rows(i)("调增单元")
r3("移动数量") = tb.rows(i)("调增数量")
r3("移动代码") = tb.rows(i)("移动代码")
r3("移动文本") = tb.rows(i)("移动文本")
r3("备注") = tb.rows(i)("备注")
r3.Save()
MessageBox.show(4)
tb.rows(i).Delete()
Dim r32 As Row = Tables("库存").AddNew() '相对增加数据
r32("物料编码") = tb2.rows(i2)("编码")
r32("移动单元") = tb2.rows(i2)("调减单元")
r32("移动数量") = tb2.rows(i2)("调减数量")
r32("移动代码") = tb2.rows(i2)("移动代码")
r32("移动文本") = tb2.rows(i2)("移动文本")
r32("备注") = tb2.rows(i2)("备注")
r32.Save()
tb2.rows(i2).Delete()
MessageBox.show(5)
................
错误提示:
.NET Framework 版本:2.0.50727.5485
Foxtable 版本:2015.11.2.1
错误所在事件:窗口,库存调整,库存调整Button1,Click
详细错误信息:
索引 1 不是为负数,就是大于行数。