Sinisterly
Tutorial .NET Remove Blanks - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework)
+--- Thread: Tutorial .NET Remove Blanks (/Thread-Tutorial-NET-Remove-Blanks)



.NET Remove Blanks - zer0_s3c - 01-06-2013

Code:
'//Remove Blanks
  Dim i As Long
  i = 0

  '' remove anything that looks like a blank
  While i < ListBox1.Items.Count
    If "" = Trim(ListBox1.Items(i).ToString) Then
    ListBox1.Items.RemoveAt(i)
    Else
    i = 1 + i
    End If
  End While
  '//

Enjoy.


RE: .NET Remove Blanks - cxS - 02-25-2013

This is more what the for loop should be used for instead as it's conditionally based off of an incremented variable. I use a while loop usually if I have to base something majorly off of a condition itself, this is more of an iteration...

And if you are having to remove blanks from items added to a ListBox, that's just wasted time. If you have to do something like this, you then should realize that what you're doing is probably poor.

Prevention is better than having to deal with it after the fact.