One or two small twiks & this worked great!! )
Thnx,
Jonathan
if ur interested:
=======================================================
Dim i As Integer, AddItem As Boolean
AddItem = True
For i = 0 To lvwAddToGroup.ListItems.Count - 1
i = i + 1
If lvwAddToGroup.ListItems(i) = strFunctionCode Then
AddItem = False
i = i - 1
End If
Next i
If AddItem = True Then
lvwAddToGroup.ListItems.Add intIndex, , strFunctionCode
lvwFunctionCode.ListItems.Remove (intDeleteItem)
End If
Are you sure?
I'm not really into your list structure, but adding to the counter inside a for loop is generally confusing.
It looks like your loop would jump every 2nd item in the list (because both 'i=i+1' and 'next i' adds 1 to i).
What about
i=0
do
If lvwAddToGroup.ListItems(i) = strFunctionCode Then
AddItem = False
Exit do
End If
i=i+1
loop until i=lvwAddToGroup.ListItems.Count
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
Well for all of the friends who are working with loops, please note one thing in your code and that is that your code keeps on looping to the end of the list, in this case let us assume we have 4 items and the second item is the one which you are trying to insert, the found flag will be true but with the next iteration it will become false again, so you need to break out of loop if you find the item in the list and then the code in the top solution will work alright like this
dim fnd as boolean
dim strToSrch as string 'whatever
fnd = false
for lp = 0 to list1.listcount - 1
if list1.list(lp) = strToSrch then
fnd = true
exit for
end if
next
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.