I have a listbox with:
Steve
John
Kara 1
Bridget 1
Sam 1
I need to add a new name between the name without the 1 and with the 1.
how can I loop through the listbox and find that position and and add the new name in that spot.
thanks
Printable View
I have a listbox with:
Steve
John
Kara 1
Bridget 1
Sam 1
I need to add a new name between the name without the 1 and with the 1.
how can I loop through the listbox and find that position and and add the new name in that spot.
thanks
Here is one of my search functions for a combo box.
http://vbforums.com/showpost.php?p=1820829&postcount=4
Then use the AddItem and specify the index position at which to insert the new item at.
VB Code:
Dim number as Integer For j = 0 To List1.ListCount frmtstr = Right(List1.List(j), 2) If frmtstr = " 1" Then Laber1.Caption = j Exit Sub End If Next j
It returns position to label1. Then you just have to add item to listbox like
List1.AddItem "newitem", number
If you have a large list then it will slow down because of the looping.
Yes, I unfortunatelly cannot deny that :cry: .Quote:
Originally Posted by RobDog888
If you dont have any or many loops then it really wont affect your apps performance too much but if you have many of them then it will definately be visible.
By creating a function and using the API non-looping method you are only makinging one call to directly find the item. If you place the function in a module and make it public then you can use it repeatly throughout your program. Less code, centralized, easier management. :)
thanks djk, im going to work with it and see if it matches what im doing...any problems ill post.