Click here to Skip to main content
15,906,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This may seem to be a simple question but the way I am going about it seems to freeze my program with no error.

I am looking to determine if a string is being added to a subitem in my listbox and if so to remove it..

here is the code I am trying to use

VB
Dim hiber As String = "hiberfil.sys"
        Dim FXSAPI As String = "FXSAPIDebugLogFile.txt"
        Dim setup1 As String = "setup-a.bin"
        Dim setup2 As String = "setup-b.bin"
  For Each ListViewItem As ListViewItem In resultsbox.Items
                                If ListViewItem.SubItems(1).Text = hiber or FXSAPI or setup1 or setup2 Then
                                    ListViewItem.Remove()
                                End If
                            Next



what other way can i achieve this?..

thank you in advance
Posted
Updated 17-Apr-13 16:58pm
v2

1 solution

Your if statement is seriously screwed. You cannot make a list of items (you're OR'ing them!) to compare a single variable to. You MUST compare the variable to each item in the list seperately. (BTW: Your ListViewItem variable name is a TERRIBLE choice since it's exactly the same as the name of a well-known class. Just call it item and be done with it.)

If ListViewItem.SubItems(1).Text = hiber or FXAPI or ...

becomes
Dim subItem As String = ListViewItem.SubItems(1).Text
If subItem = hiber Or subItem = FXSAPI Or subitem = setup1 Or subItem = setup2 Then ...


This is a VB.NET (or any other language) 101 thing. You REALLY need to pickup a beginners book on VB.NET and work through it.
 
Share this answer
 
Comments
Dale 2012 17-Apr-13 23:45pm    
Very true I should be a bit more careful when naming variables thank you for this example!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900