Sign in to follow this  
Followers 0
Chance

Confusing array filter

1 post in this topic

To tell you the truth, math is nowhere near my strong side, I'm having a lot of trouble getting this into my head, I don't know why it's not working and how to fix it...

I've added a few comments that will hopefully show what it's I'm trying to do in here :/

#include <Array.au3>

#region - test 1 -

Local $New_Data_to_Add[1] = ['[["123",5]]']; data that will be added or should stay if already on listview
Local $Currently_In_List[3] = ["123", "456","789"];data that was in list view prior to this call
Filter($New_Data_to_Add, $Currently_In_List)
_ArrayDisplay($New_Data_to_Add, "$New_Data_to_Add"); data that will be newly added to listview
_ArrayDisplay($Currently_In_List, "$Currently_In_List"); data that should remain in list view

#cs
    in this example,$New_Data_to_Add is handled correctly and returns zero in place of 123 which was already in current list
    problem is that $Currently_In_List should only return 123 and not 456 and 789
#ce

#endregion - test 1 -
Exit
#region - test 2 -

Local $New_Data_to_Add[1] = ['[["123",2],["456",8],["789",1]]']; data that will be added or should stay if already on listview
Local $Currently_In_List[3] = ["123", "456"];data that was in list view prior to this call
Filter($New_Data_to_Add, $Currently_In_List)
_ArrayDisplay($New_Data_to_Add, "$New_Data_to_Add"); data that will be newly added to listview
_ArrayDisplay($Currently_In_List, "$Currently_In_List"); data that should remain in list view

#cs
    in this example,$New_Data_to_Add is handled correctly, only 789 remains positive and will be added to list
    problem is that $Currently_In_List is not returning 123 and 456 which should remain in the array..., or should not be touched aka deleted from list
#ce

#endregion - test 2 -

Func Filter(ByRef $New_Data_to_Add, ByRef $Currently_In_List)

    $Result = StringRegExp($New_Data_to_Add[0], '\["([^"\]]\d*)",([^\]]\d*)', 3)
    If @error Then
        Return SetError(1, 0, 0)
    EndIf

    Local $Count = 0
    Local $New[999][2]

    For $I = 1 To UBound($Result) - 1 Step 2
        $New[$Count][0] = $Result[$I-1]
        $New[$Count][1] = $Result[$I]
        $Count += 1
    Next

    If $Count Then ReDim $New[$Count][2]

    Local $ID, $Delete

    For $O = 0 To 10
        If Not IsArray($New) Then Return
        $Count = UBound($Currently_In_List)-1;_GUICtrlListView_GetItemCount($blah)
        For $I = 0 To $Count
            $ID = $Currently_In_List[$I];_GUICtrlListView_GetItemText($blah, $I, 0)
            For $X = 0 To UBound($New)-1
                If $New[$X][0] Then
                    $Delete = 1
                    If $ID == $New[$X][0] Then
                        $Delete = 0; mark
                        $New[$X][0] = 0
                        ;_GUICtrlListView_SetItemText($blah, $I, $New[$X][1], 1); update info, usually works
                        ExitLoop
                    EndIf
                Else
                    $Delete = 0
                EndIf
            Next
            If $Delete Then
                ;_GUICtrlListView_DeleteItem($blah, $I); this is supposed to delete anything that's not in the $New_Data_to_Add array
                _ArrayDelete($Currently_In_List, $I)
                ExitLoop
            EndIf
        Next
    Next

    $New_Data_to_Add = $New

    Return
EndFunc

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0