下标在MSFlexgrid中超出范围

时间:2016-10-26 13:28:40

标签: vb6

我在VB6中使用msflexgrid。如何删除或解决以下错误:

  

下标超出范围。

With flxData(0)
  For i = 1 To .Rows - 1
    Do While cboselect <> .TextMatrix(i, 1)
      .RemoveItem (i)
    Loop
  Next i
End with

1 个答案:

答案 0 :(得分:1)

刚刚意识到Do While循环内部的For循环会导致错误显示 - 一旦某行没有所需的cboselect值,就会#39 ;为了那个和所有剩余的行,打算调用RemoveItem,直到它们全部被删除,然后它在尝试删除(现在)不存在时显示该消息行。

我猜你想要删除与cboselect值不匹配的行,这样就会调用If语句。您还需要向后运行For循环。试试这个:

With flxData(0)
  For i = .Rows - 1 to 1 Step -1
    If cboselect <> .TextMatrix(i, 1) Then
      .RemoveItem (i)
    End If
  Next i
End With