Jump to content

Okay, stop looping now


Recommended Posts

I have two arrays.

This is array #1 ($MP3Array):

[0] 3

[1] testaudio01

[2] testaudio02

[3] tesaudio03

This is array #2 ($WrecArray):

[0] 3

[1] testaudio02

[2] testaudio03

[3] testaudio05

I want to search each item in array #2 to see if it matches an item in array #1. I can do that with this function:

Func WhatCanBurn()
    StartFunc("WhatCanBurn()")
    ; go through each index in the mp3 array and see if it has a corresponding wrec 
    _ArraySort($MP3Array)
    _ArraySort($WrecArray)
    LogIt("Arrays sorted")
    ;_ArrayDisplay($MP3Array, "mp3")
    ;_ArrayDisplay($WrecArray, "wrec")
    LogIt("Searching for MP3s with corresponding wrecs")
    $CannotBurnArray = _ArrayCreate(0)
    For $i = 1 to $MP3Array[0]
        For $j = 1 to $WrecArray[0]
            If $MP3Array[$i] = $WrecArray[$j] Then
                LogIt("MATCH!: " & $MP3Array[$i] & " matches " & $WrecArray[$j] & " -- cannot burn this mp3")
                _ArrayAdd($CannotBurnArray, $MP3Array[$i])
                $CannotBurnArray[0] = $CannotBurnArray[0] + 1
            Else
                LogIt("No match with " & $MP3Array[$i] & " & " & $WrecArray[$j])
            EndIf
        Next
        $NoBurn = 0
    Next
    _ArrayDisplay($CannotBurnArray, "cannot burn")
    FinaliseArray()
EndFunc

It seems to work too - it deletes the items from $MP3Array. But I can't get it to stop! It seems to be trying to find/delete things even after it has reached the limit of the array.

Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

If $MP3Array[$i] = $CannotBurnArray[$j] Then

If ^ ERROR

This is something really really simple but I can't figure it out! I'm using pretty much the same process to compare two arrays in my first function (WhatCanBurn), and I have combed through both functions trying to find what I'm doing wrong, and I have mixed around some lines of code and some numbers but still can't get it to work. Maybe someone here has better eyes for this sort of thing? muttley
Link to comment
Share on other sites

When you are deleting things from an array, walk it in REVERSE so deleting one index does not impact the next ones you check:

For $i = $MP3Array[0] To 1 Step -1
        For $j = 1 To $CannotBurnArray[0]
            ; ...the rest of the code
        Next
    Next

muttley

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...