1

我正在运行一个直到循环并且它给出的错误索引超出范围。我正在使用这段代码:

If Not imgList.Item(i).ToString = Nothing Then

但它不起作用..实际上这个循环(在私有子中)是在列表框中添加任何值之前调用的..

这是完整的循环..

Dim i As Integer = 0

Do Until i = pagesRange
       If Not imgList.Item(i).ToString = Nothing Then
          'other code
          i += 1

       Else

       End If
Loop
4

2 回答 2

1

对于给定的代码,以避免索引超出范围异常尝试下面

If imgList.Count < i AndAlso Not (imgList.Item(i).ToString Is Nothing) Then

End If
于 2013-06-08T16:52:03.987 回答
0

记住基于零的..

Dim i As Integer = 0

Do Until i = pagesRange -1
       If Not imgList.Item(i).ToString = Nothing Then
          'other code
          i += 1

       Else

       End If
       'why i += 1 not here ?
Loop
于 2013-06-08T23:21:39.530 回答