Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
If else statements are really not the issue but in my case I am using regular expressions and match collection to add matches found to a listview else write values to a local database but for some reason the else statement is not acting as it should and writes all values to my local database?.. any ideas are appreciated as to why its writing all but ignoring the else statement.

VB
Dim matches1 As MatchCollection = Engine.CLAM_VIRUS_NAME.Matches(VReader)
    For Each Newmatch As Match In matches1
        For Each s As String In Subtract__List
            Dim Split_S() As String = Split(s, "|")
            Dim FS As String = Split_S(0)
            Dim OFP As String = Split_S(1)
            If M.Success = True AndAlso s.Contains(File_Name.Value) = True Then
                Add_Listview_Records(OFP, VN.Value, File_Name.Value, FS)
                For upIndex = ListView1.Items.Count - 1 To 1 Step -1
                    Dim upItem = ListView1.Items(upIndex)
                    For downIndex = 0 To upIndex - 1 Step 1
                        Dim downItem = ListView1.Items(downIndex)
                        If AreEquivalent(upItem, downItem) Then
                            ListView1.Items.Remove(upItem)
                            Exit For
                        End If
                    Next
                Next
            Else
                Engine.Insert_Access_Records(FS)
            End If
        Next
        Label8.Text = CStr(ListView1.Items.Count)
       VN = VN.NextMatch
        File_Name = File_Name.NextMatch
    Next Newmatch


I Know it must have something todo with the logic of the code but however I try it will still write all values instead of only the matches that are not found.

thank you in advance!
Posted
Comments
PIEBALDconsult 11-Aug-15 11:13am    
The if doesn't seem to check anything to do with the matches.
Have you stepped through with the debugger and looked at the values?
ZurdoDev 11-Aug-15 11:24am    
Not really sure what your question is. However, all you have to do is debug the code and you'll see exactly what is happening.
Sergey Alexandrovich Kryukov 11-Aug-15 11:47am    
There is no such thing as "if else statement" problem. Just use the debugger.
—SA
Aravindba 11-Aug-15 21:41pm    
Try this how can use break point and checking each and every line with values
https://www.youtube.com/watch?v=w1777MupP_A
If "else" statement not active means,ur "If" condition satisfy with values.
DamithSL 11-Aug-15 23:27pm    
What is M? may be M.Success is always false, debug and check

Um...did you mean
VB
If M.Success = True AndAlso s.Contains(File_Name.Value) = True Then

Given that M doesn't change at all inside either of your loops.

If that doesn't solve it, you need to use the debugger to step through each line, working out what you expect to happen before each statement executes and comparing that against the actual results. Remember that you can look at the content of each variable as you go. When you find something that isn't right...then you can look more closely.

We can't do that for you - we don't have access to your code or your data.
 
Share this answer
 
Hi Try this how can use break point and checking each and every line with values
https://www.youtube.com/watch?v=w1777MupP_A[^]

If "else" part not active means,ur "If" part satisfy with values.

or try to following ways and check

if both must true then use this
VB
If M.Success = True And s.Contains(File_Name.Value) = True Then

for checking purpose u change "=" to "<>" and check it reach else part
VB
If M.Success <> True And s.Contains(File_Name.Value) <> True Then
 
Share this answer
 
v2
Comments
Draco2013 12-Aug-15 11:01am    
after what seemed like fail after fail I finally figured out that the problem was due to the contains not being the same and adding values not intended. Thank you everyone for the solutions. Stepping through the code is very beneficial and necessary.

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