 |
patkam Level: Scholar
 Registered: 19-04-2004 Posts: 36
|
Re: Unexpected behavior with for each loop
Why not use Do While loops? e.g.
bNewItem = True
intExistingRow = 0
Do While intExistingRow < listBoxCurrentInventoryItems.ListCount
strExistingItem = listBoxCurrentInventoryItems.ItemData(intExistingRow)
if strQueuedItem = strExistingItem then
bNewItem = False
Exit Do
end if
intExistingRow = intExistingRow + 1
Loop |
You should stop comparing once it's found - to cut meaningless iterations: "Exit Do" (Assume new, then stop searching if found! Consider a match on item 1 on a 100,000 items list. We need to consider performance while coding!)
One more thing! In case your list is so large that it's more than 65536 items (or the max of integer), you should use the type long instead of int, to reduce chance of overflow.
____________________________
Knowledge is there to share, not to hide!
-< PATKAM >-
|
|
14-04-2009 at 04:12 PM |
|
|
|
|
 |
 |