LoneWolf_2106

Nested for - inner for skipped

2 posts in this topic

#1 ·  Posted (edited)

Dear everybody,

i have created a function that searches for a string in an array and starting from that point(index), stores in another array the following 26 items.

Func FileSearch($sStringToSearch)
    $k=0
    $count_search=0
    For $count = 0 To UBound($content_array) - 1
            $search_result=StringInStr($content_array[$count],$sStringToSearch)
                If $search_result<>0  Then
                    $count_search+=1
                    ReDim $SearchOnlineActivation[$count_search][$k] ;Adding a row
                    MsgBox($MB_OK, "rows", UBound($SearchOnlineActivation, $UBOUND_ROWS))
                    For $k=0 To 25
                        ReDim $SearchOnlineActivation[$count_search][$k +1] ;Adding a column
                        $SearchOnlineActivation [$count_search -1][$k] = $content_array[$count]
                        $k+=1
                        ;_ArrayDisplay($SearchOnlineActivation)
                        Next
                EndIf
    Next
EndFunc

 

The problem starts at this Point:

$SearchOnlineActivation [$count_search -1][$k] = $content_array[$count]

I insert a search_result in a cell of the 2D Array, but it "crashes". (Array variable has incorrect number of subscripts or subscript dimension range exceeded.)

Edited by LoneWolf_2106

Share this post


Link to post
Share on other sites



#2 ·  Posted

Couple of thoughts --

1) ReDim is slow. Move it out of your For loop and do it once instead of 25 times

2) If $k = 0, then $k - 1 = -1, which is an invalid subscript dimension. Try changing that line to

$SearchOnlineActivation [$count_search -1][$k] = $content_array[$count]

 

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