1
在我的循環中,我嘗試從具有特定名稱的列表中刪除項目。我不能用for-each來做到這一點,所以我嘗試了一個常規for循環。看來for循環沒有按預期工作。它總是超越極限。我不得不把一個if-then打破循環(非常醜陋的解決方案)。我試圖找到正確的方法來完成這一點。更改增量變量會導致循環超出限制
Dim canShowNextTable As Boolean = False
Dim allTablesInTab As List(Of Control) = ctrlFinder.GetTypeOfControls("Table", parentForm.Controls)
Dim totalTables As Integer = allTablesInTab.Count - 1
For i As Integer = 0 To totalTables
If allTablesInTab.Item(i).ID = "CustomerTable" Or _
allTablesInTab.Item(i).ID = "PMTable" Or _
allTablesInTab.Item(i).ID = "TableAListClrnCheck" Or _
allTablesInTab.Item(i).ID = "TableBListClrnCheck" Or _
allTablesInTab.Item(i).ID = "TableCListClrnCheck" Or _
allTablesInTab.Item(i).ID = "TableDListClrnCheck" Or _
allTablesInTab.Item(i).ID = "TableSignature" Then '' If the ID is one of these remove it from list
allTablesInTab.Remove(allTablesInTab.Item(i))
totalTables = totalTables - 1 '' Decrement number of tables to loop through
i = -1 '' Reset counter to prevent going over or premature stopping
End If
If i = 3 AndAlso totalTables = 3 Then '' Since loop continuously goes over limit, use if-then to exit for-loop
Exit For
End If
Next
+1你可能需要考慮增加的語法。 – 2010-11-04 15:08:41
@康拉感謝,你可能已經抓住我中期編輯:) – 2010-11-04 15:12:37
謝謝先生們。它像一個魅力。 – dotnetN00b 2010-11-04 15:23:28