473,799 Members | 2,934 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to remove blank items from listbox?

5 New Member
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 12209
Oralloy
988 Recognized Expert Contributor
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 Recognized Expert Moderator MVP
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
Connect
5 New Member
didnot work
Jan 26 '11 #4
Connect
5 New Member
didnot work orally
Jan 26 '11 #5
Oralloy
988 Recognized Expert Contributor
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
cpanelxp
6 New Member
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 Recognized Expert Contributor
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, 565 views)
Jan 27 '11 #8
cpanelxp
6 New Member
my friend this code for ms excel
and I want for code vb.net
thanks again
Jan 27 '11 #9
Oralloy
988 Recognized Expert Contributor
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

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

Similar topics

3
19574
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
11933
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 = eval("document." + formName) if (confirm("Are you sure you want to remove this item?"))
4
4769
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 the email address)
2
6520
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 array to contain "blank" string/line/carriage return How do i remove the index so that my arraylist become smaller ?
7
2037
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
8808
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
4467
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 I deleted 450 rows & is there any way to do this using VB? Please guide me. Thanx & regards, Prem
3
2573
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
25652
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 items (either one at a time or several). I found some code at this website: http://www.599cd.com/tips/access/listbox-additem-2000/ The author suggests creating a Text Box, then first temporarily storing the text that is selected in the List Box...
2
2195
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 insert it in a database table. But first value of each row aoutomatically appends two blank spaces, even if there are no blank spaces at the begining of each row. I tried to use "TRIM/LTRIM/Replace" to remove blank spece from the first value of...
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.