473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to remove blank items from listbox?

hi i have qusetion
how to remove ongy blank items from listbox?
I mean I wanna make button that only remove blank items from listbox
Jan 25 '11 #1
13 12128
Oralloy
988 Expert 512MB
Connect,

Just loop over the elements in the list, and if any is blank, remove it.

Expand|Select|Wrap|Line Numbers
  1. Dim l As MSForms.ListBox
  2. Dim i As Long: i = 0
  3. While i < l.ListCount
  4.  If "" = l.List(i, 0) Then: l.RemoveItem (i): Else i = 1 + i
  5. Wend
Cheers!
Oralloy
Jan 25 '11 #2
Rabbit
12,516 Expert Mod 8TB
I'm assuming the data is coming from a database. You could just not return the blank rows when retrieving the data from the database.
Jan 25 '11 #3
didnot work
Jan 26 '11 #4
didnot work orally
Jan 26 '11 #5
Oralloy
988 Expert 512MB
Connect,

Frist off, I assume that you set the variable l to your list box, like this:
Expand|Select|Wrap|Line Numbers
  1. Set l = Me.ListBox1
Also, if your "blank" items are strings of blanks, you'll have to use Trim$ to remove the extra spaces:
Expand|Select|Wrap|Line Numbers
  1. Dim l As MSForms.ListBox 
  2. Set l = Me.ListBox1
  3.  
  4. Dim i As Long: i = 0
  5.  
  6. While i < l.ListCount 
  7.  If "" = Trim$(l.List(i, 0)) Then: l.RemoveItem (i): Else i = 1 + i 
  8. Wend 
So - did you see any errors, and where did you put the code?
Jan 27 '11 #6
I have same problom Oralloy
and your code didnt work with me
could you attach editale file if this code
Jan 27 '11 #7
Oralloy
988 Expert 512MB
cpanelxp,

Here is a fully functional demonstration of a list and code to clean it.

Luck!
Oralloy
Attached Files
File Type: zip Clean List.zip (14.4 KB, 564 views)
Jan 27 '11 #8
my friend this code for ms excel
and I want for code vb.net
thanks again
Jan 27 '11 #9
Oralloy
988 Expert 512MB
Hopefully I'm not wasting your time.

The logic is the same, the only differences are minor details (although I do recognize that the details can be very painful). The essential code loop should be as follows, although you will have to change the control name to whatever yours is:

Expand|Select|Wrap|Line Numbers
  1.   '' index variable
  2.   Dim i As Long
  3.   i = 0
  4.  
  5.   '' remove anything that looks like a blank
  6.   While i < ListBox1.Items.Count
  7.     If "" = Trim(ListBox1.Items(i).Text) Then
  8.       ListBox1.Items.RemoveAt(i)
  9.     Else
  10.       i = 1 + i
  11.     EndIf
  12.   Wend
Jan 27 '11 #10
Rabbit
12,516 Expert Mod 8TB
Shouldn't you just make sure no blank records are used for the list in the first place? Instead of removing the blanks after inserting them.
Jan 27 '11 #11
Oralloy
988 Expert 512MB
Rabbit,

That's probably the best approach; proper data selection beats data conditioning any day of the week.

I'm just hoping he hasn't bound the list to a source in such a way that he can't modify it in a reasonable fashion.
Jan 27 '11 #12
thank you very muck mr.Oralloy
THAT'S IT
works successfully
Jan 27 '11 #13
Oralloy
988 Expert 512MB
Glad we could help you out.

Good Luck!
Oralloy
Jan 27 '11 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: darren | last post by:
How, using asp.net (vb.net), can I remove multiple selected items from a listbox. Everything I try does not seem to work. Thanks in advance.
1
by: Suresh | last post by:
formName: Name of the form ctrlListBox: Name of the Listbox control function fnRemoveListItem(formName, ctrlListBox) { if (formName == '') var formName = document.forms(0).name obj =...
4
by: rdi | last post by:
Why does the following NOT remove the items from the ListView? I need to remove all the items and re-build the LV based on new information. Thanks. -- RDI (remove the exclamation from...
2
by: James | last post by:
below is some codes. my arraylist below reads from a file. My files contains blank line (ie carriage return) My message dialog shows all strings being captured. However i do not want my...
7
by: Mike Johnson | last post by:
How do I remove a item that's been selected from a listview? I'm using Visual Basic 2005 express edition. Thanks
3
kamill
by: kamill | last post by:
how can i remove blank spaces from text file......is there any function to remove a perticular chr from file...
1
by: premMS143 | last post by:
Hi 1 & all, Using VB, How to remove blank rows in a Excel worksheet? For example, I'm having a Excel sheet containing 900 rows data, in which there are blank rows inserted in between. Manually...
3
by: esperanto234 | last post by:
Hi, I need a code to remove all the items that are unselected from a listbox. I really need this!! Thanks!!
10
by: errol999 | last post by:
I'm using Access 2003. I have a List Box which I populate by selecting items from a drop down Combo Box. I now want to delete from the List Box only the selected, but not necessarily sequencial...
2
by: SwapnilD | last post by:
I'm implementing a feature which reads comma separated txt file from server(one line at a time). Format of file is fixed, There are 3 columns on each row. After reading the row from file I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.