Search code examples
arrayssizekeywordautoitreduce

In Autoit script, does Redim be unusable in decreasing array size?


I written an Autoit script. But error occured in the point of using Redim keyword which is used for the purpose of decreasing array size with keeping existing contents.

The test script is

#include-once
#include <Array.au3>
#include <File.au3>
#include <String.au3>

Local $_URLfile = InputBox("filename input","Please input your URL-list filename with path")
$_URLfile       = StringReplace($_URLfile,'"',"") ; remove quotation mark in filename

Local $_urllistarray
_FileReadToArray($_URLfile, $_urllistarray)       ; read each line of the file and store to array

Local $_ValidUrlList[$_urllistarray[0]]

; restore to another array except elements which are empty or not Url string elements
Local $i = 0
For $j = 1 To $_urllistarray[0]
    If StringRegExp($_urllistarray[$j],'(^http)') And StringLen($_urllistarray[$j]) >= 15 Then
        $_ValidUrlList[$i]=$_urllistarray[$j]
        $i += 1
    Else
        Redim $_ValidUrlList[UBound[$_ValidUrlList]-1] ; but, ERROR occures here
    EndIf
Next

_ArrayDisplay($_ValidUrlList,"ValidUrlList")

Error message is

==> Subscript used on non-accessible variable.:
Redim $_ValidUrlList[UBound[$_ValidUrlList]-1]
Redim $_ValidUrlList[UBound^ ERROR
>Exit code: 1    Time: 32.72

How can I fix this error? Or, is it impossible to decrease array size with Redim keyword? I'm looking for your help. Thank you:-)


Solution

  • Redim $_ValidUrlList[UBound[$_ValidUrlList]-1]
    

    should be

    Redim $_ValidUrlList[UBound($_ValidUrlList)-1]
    

    because UBound isn't an array...