求循环代码,该怎么解决
求循环代码本帖最后由 bcrun 于 2012-12-07 20:15:09 编辑当vsflexgrid指定單元格不为空时增加新行下面是
求循环代码
本帖最后由 bcrun 于 2012-12-07 20:15:09 编辑 当vsflexgrid指定單元格不为空时增加新行
下面是我的代码,达不到效果。
Dim i As Integer
Dim j As Integer
For i = 1 To fg.Rows - 1
For j = 0 To fg.Cols - 2
If fg.TextMatrix(i, j) = "" Then
MsgBox fg.TextMatrix(0, j) & "不能為空!"
Exit for
Else
fg.Rows = fg.Rows + 1
End If
Next
请帮忙修改!
[解决办法]在循环体内修改了循环的上限fg.Rows,如果存在条件,应该会死机吧.
内存循环用了exit for,条件是某一行存在空单元格就退出内存循环...没去扫描后续这一行的其他单元格.
你的意思是:有多少个空单元格,就增加多少个行?
那应该先扫描有多个个空单元格,然后在一次增加若干个行,这样控件刷新次数少,有效率.
Dim i As Integer
Dim j As Integer
dim count as integer
For i = 1 To fg.Rows - 1
For j = 0 To fg.Cols - 2
If fg.TextMatrix(i, j) = "" Then
MsgBox fg.TextMatrix(i, j) & "不能為空!"
Exit for
Else
count = count + 1
End If
Next j
next i
if count<>0 then fg.Rows = fg.Rows + count
[解决办法]Dim i As Integer
Dim j As Integer
dim count as integer
For i = 1 To fg.Rows - 1
For j = 0 To fg.Cols - 2
If fg.TextMatrix(i, j) = "" Then
MsgBox fg.TextMatrix(i, j) & "不能為空!"
Exit for
Else
count = count + 1
End If
Next j
next i
if count<>0 then fg.Rows = fg.Rows + count