| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
VB Removing Items from list Box
|
Original Message
|
Name: iggster
Date: March 9, 2004 at 04:43:51 Pacific
Subject: VB Removing Items from list Box OS: Win XP CPU/Ram: 512mb
|
Comment: Hi In my VB program i add items from a text file. The problem is in the text box i have serval pieces of information. One of the pieces is and Examboard Id which is the subject of this list box. When clicked it loads up all the exam courses in another listbox. But in the Examboard ID list box the exam board id for say one company ocurrs more than once and is displayed more than once. I wanna know how I can remove any reacurring information in this listbox. does anyone know how i can do this??? Many Thanks in Return Tim
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: StuartS
Date: March 9, 2004 at 07:30:39 Pacific
|
Reply: (edit) Use List1.RemoveItem (3) 3 being the item in the list to be removed. A sorted list and a For/next loop should help you remove duplicate items. For a = 1 To List1.ListCount If List1.List(a) = List1.List(a - 1) Then List1.RemoveItem (a) End If Next Bare in mind that once item 3 is removed, item 4 then becomes item 3 and so on. I have not tested this code so it may throw up a few errors once you start removing items. Repeatedly executing Remove(3) will clear the List until there is only Items 0,1,2 left. Stuart
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
|
Reply: (edit)what i think you should do is store each value into a variable, check if that value is already in the list box. eg load EACH value from a file dim Value as string Value = 'value from file' for i = 0 to list1.listcount if list1.list(i) = value then msgbox "VAlue already exists" exit for else list1.additem value end if next i This will prevent any duplicate values from being loaded into the listbox in the first place. It works i have tried it so i hope it helps
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: StuartS
Date: March 9, 2004 at 09:54:56 Pacific
|
Reply: (edit)It will work, but oh so slowly. It needs to go though the For/Next loop for every item added, a For/Next loop that gets bigger with every item. With the method I described it only goes through a For/next loop once. One way to speed things up, whichever method is used, is to set the list box property visible = false until its all done then set visible = true. Stuart
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
|
Reply: (edit)Very true and a very good idea. My code by the way was slightly wrong, i done the code and never saved it and then i wrote it here on the fly, so there is a bg but if you decide to use it ull work it out.
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Programming Forum Home