Sign in to follow this  
Followers 0
vatobeto

Getting Error in Array.au3

2 posts in this topic

#1 ·  Posted (edited)

I am getting this error - what to do?

Apparently the call to _ArrayDisplay is triggering this.

The scripting dictionary method Keys does produce an array, right?

C:\Program Files\AutoIt3\Include\Array.au3 (184) : ==> Array variable subscript badly formatted.:

ReDim $ar_2dCurrent[uBound($ar_2DArray) ][1]

ReDim $ar_2dCurrent[^ ERROR

->15:42:55 AutoIT3.exe ended.rc:1

>Exit code: 1 Time: 1.528

Using Vista SP1

My code (unfinished):

CODE
#include <File.au3>

#include <Date.au3>

#include <Array.au3>

;Produce List of Files in Folder by Type

;Scripting Dictionary Functions Courtesy of GaryFrost - THX,

;Sort Dictionary routine from MS VBScript post #246067

Global $oDictionary, $oMyError

Const $dictKey = 0

Const $dictItem = 1

$pattern1 = "^(.*)\.([\w\d]{3,4})$"

$pattern2 = "\1"

$pattern3 = "\2"

Dim $arr1[4] = ["a.au3","b.au3","c.au3","d.au3"]

Dim $arr2[4] = ["a.exe","x.exe","y.exe","z.exe"]

Dim $arr3[3] = ["j.doc","c.doc","z.doc"]

Dim $kArray[1]

Dim $FileArray[1]

Dim $FolderArray[1]

$oDictionary = _InitDictionary()

SortDictionary($oDictionary, $dictKey)

$kArray = $oDictionary.keys

_ArrayDisplay($kArray)

MsgBox(0,"Folder List","Folder List")

$var = FileSelectFolder("Choose a folder.", "", 6)

$tempoutname = "FileListThisFolder" & _Date_Time_GetTickCount() & ".txt"

$outFile = FileOpen($var & "\" & $tempoutname, 2)

; Shows the filenames of all files in the current directory.

$search = FileFindFirstFile($var & "\" & "*.*")

; Check if the search was successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

If StringRegExp($file, $pattern1) Then

_ArrayAdd($FileArray, $file)

Else

_ArrayAdd($FolderArray, $file)

EndIf

; FileWrite($outFile, $file & @CRLF)

WEnd

_ArraySort($FolderArray, 0)

WriteFileList()

; Close the search handle

FileClose($search)

FileClose($outFile)

MsgBox(0,"Finished","List File Created In Host Folder")

Exit

Func _InitDictionary()

Return ObjCreate("Scripting.Dictionary")

EndFunc ;==>_InitDictionary

; Adds a key and item pair to a Dictionary object.

Func _AddItem($v_key, $v_item)

$oDictionary.ADD ($v_key, $v_item)

If @error Then Return SetError(1, 1, -1)

EndFunc ;==>_AddItem

; Returns true if a specified key exists in the Dictionary object, false if it does not.

Func _ItemExists($v_key)

Return $oDictionary.Exists ($v_key)

EndFunc ;==>_ItemExists

; Returns an item for a specified key in a Dictionary object

Func _Item($v_key)

Return $oDictionary.Item ($v_key)

EndFunc ;==>_Item

; Sets an item for a specified key in a Dictionary object

Func _ChangeItem($v_key, $v_item)

$oDictionary.Item ($v_key) = $v_item

EndFunc ;==>_ChangeItem

; Sets a key in a Dictionary object.

Func _ChangeKey($v_key, $v_newKey)

$oDictionary.Key ($v_key) = $v_newKey

EndFunc ;==>_ChangeKey

; Removes a key, item pair from a Dictionary object.

Func _ItemRemove($v_key)

$oDictionary.Remove ($v_key)

If @error Then Return SetError(1, 1, -1)

EndFunc ;==>_ItemRemove

; Returns the number of items in a collection or Dictionary object.

Func _ItemCount()

Return $oDictionary.Count

EndFunc ;==>_ItemCount

; Returns an array containing all the items in a Dictionary object

Func _GetItems()

Return $oDictionary.Items

EndFunc ;==>_GetItems

Func SortDictionary(ByRef $objDict,$intSort)

; declare our variables

Local $vbTextCompare = 0

Dim $strDict[1][1]

Local $objKey

Local $strKey,$strItem

Local $X,$Y,$Z

; get the dictionary count

$Z = $objDict.Count

; we need more than one item to warrant sorting

If $Z > 1 Then

; create an array to store dictionary information

ReDim $strDict[$Z][2]

$X = 0

; populate the string array

For $objKey In $objDict

$strDict[$X][$dictKey] = $objKey & ""

$strDict[$X][$dictItem] = $objDict.item($objKey) & ""

$X = $X + 1

Next

; perform a a shell sort of the string array

For $X = 0 to ($Z - 2)

For $Y = $X to ($Z - 1)

If StringCompare($strDict[$X][$intSort],$strDict[$Y][$intSort]) > 0 Then

$strKey = $strDict[$X][$dictKey]

$strItem = $strDict[$X][$dictItem]

$strDict[$X][$dictKey] = $strDict[$Y][$dictKey]

$strDict[$X][$dictItem] = $strDict[$Y][$dictItem]

$strDict[$Y][$dictKey] = $strKey

$strDict[$Y][$dictItem] = $strItem

EndIf

Next

Next

; erase the contents of the dictionary object

$objDict.RemoveAll

; repopulate the dictionary with the sorted information

For $X = 0 to ($Z - 1)

$objDict.Add($strDict[$X][$dictKey], $strDict[$X][$dictItem])

Next

EndIf

EndFunc

Func WriteFileList()

FileWrite($outFile, $var & @CRLF & "FOLDERS:" & @CRLF & @CRLF)

For $i = 1 To UBound($FolderArray)-1

FileWrite($outFile, $FolderArray[$i] & @CRLF)

Next

EndFunc

Any help is greatly appreciated.

vatobeto.

Edited by vatobeto

Share this post


Link to post
Share on other sites



I am getting this error - what to do?

Apparently the call to _ArrayDisplay is triggering this.

The scripting dictionary method Keys does produce an array, right?

C:\Program Files\AutoIt3\Include\Array.au3 (184) : ==> Array variable subscript badly formatted.:

ReDim $ar_2dCurrent[uBound($ar_2DArray) ][1]

ReDim $ar_2dCurrent[^ ERROR

->15:42:55 AutoIT3.exe ended.rc:1

>Exit code: 1 Time: 1.528

Using Vista SP1

My code (unfinished):

CODE
#include <File.au3>

#include <Date.au3>

#include <Array.au3>

;Produce List of Files in Folder by Type

;Scripting Dictionary Functions Courtesy of GaryFrost - THX,

;Sort Dictionary routine from MS VBScript post #246067

Global $oDictionary, $oMyError

Const $dictKey = 0

Const $dictItem = 1

$pattern1 = "^(.*)\.([\w\d]{3,4})$"

$pattern2 = "\1"

$pattern3 = "\2"

Dim $arr1[4] = ["a.au3","b.au3","c.au3","d.au3"]

Dim $arr2[4] = ["a.exe","x.exe","y.exe","z.exe"]

Dim $arr3[3] = ["j.doc","c.doc","z.doc"]

Dim $kArray[1]

Dim $FileArray[1]

Dim $FolderArray[1]

$oDictionary = _InitDictionary()

SortDictionary($oDictionary, $dictKey)

$kArray = $oDictionary.keys

_ArrayDisplay($kArray)

MsgBox(0,"Folder List","Folder List")

$var = FileSelectFolder("Choose a folder.", "", 6)

$tempoutname = "FileListThisFolder" & _Date_Time_GetTickCount() & ".txt"

$outFile = FileOpen($var & "\" & $tempoutname, 2)

; Shows the filenames of all files in the current directory.

$search = FileFindFirstFile($var & "\" & "*.*")

; Check if the search was successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

If StringRegExp($file, $pattern1) Then

_ArrayAdd($FileArray, $file)

Else

_ArrayAdd($FolderArray, $file)

EndIf

; FileWrite($outFile, $file & @CRLF)

WEnd

_ArraySort($FolderArray, 0)

WriteFileList()

; Close the search handle

FileClose($search)

FileClose($outFile)

MsgBox(0,"Finished","List File Created In Host Folder")

Exit

Func _InitDictionary()

Return ObjCreate("Scripting.Dictionary")

EndFunc ;==>_InitDictionary

; Adds a key and item pair to a Dictionary object.

Func _AddItem($v_key, $v_item)

$oDictionary.ADD ($v_key, $v_item)

If @error Then Return SetError(1, 1, -1)

EndFunc ;==>_AddItem

; Returns true if a specified key exists in the Dictionary object, false if it does not.

Func _ItemExists($v_key)

Return $oDictionary.Exists ($v_key)

EndFunc ;==>_ItemExists

; Returns an item for a specified key in a Dictionary object

Func _Item($v_key)

Return $oDictionary.Item ($v_key)

EndFunc ;==>_Item

; Sets an item for a specified key in a Dictionary object

Func _ChangeItem($v_key, $v_item)

$oDictionary.Item ($v_key) = $v_item

EndFunc ;==>_ChangeItem

; Sets a key in a Dictionary object.

Func _ChangeKey($v_key, $v_newKey)

$oDictionary.Key ($v_key) = $v_newKey

EndFunc ;==>_ChangeKey

; Removes a key, item pair from a Dictionary object.

Func _ItemRemove($v_key)

$oDictionary.Remove ($v_key)

If @error Then Return SetError(1, 1, -1)

EndFunc ;==>_ItemRemove

; Returns the number of items in a collection or Dictionary object.

Func _ItemCount()

Return $oDictionary.Count

EndFunc ;==>_ItemCount

; Returns an array containing all the items in a Dictionary object

Func _GetItems()

Return $oDictionary.Items

EndFunc ;==>_GetItems

Func SortDictionary(ByRef $objDict,$intSort)

; declare our variables

Local $vbTextCompare = 0

Dim $strDict[1][1]

Local $objKey

Local $strKey,$strItem

Local $X,$Y,$Z

; get the dictionary count

$Z = $objDict.Count

; we need more than one item to warrant sorting

If $Z > 1 Then

; create an array to store dictionary information

ReDim $strDict[$Z][2]

$X = 0

; populate the string array

For $objKey In $objDict

$strDict[$X][$dictKey] = $objKey & ""

$strDict[$X][$dictItem] = $objDict.item($objKey) & ""

$X = $X + 1

Next

; perform a a shell sort of the string array

For $X = 0 to ($Z - 2)

For $Y = $X to ($Z - 1)

If StringCompare($strDict[$X][$intSort],$strDict[$Y][$intSort]) > 0 Then

$strKey = $strDict[$X][$dictKey]

$strItem = $strDict[$X][$dictItem]

$strDict[$X][$dictKey] = $strDict[$Y][$dictKey]

$strDict[$X][$dictItem] = $strDict[$Y][$dictItem]

$strDict[$Y][$dictKey] = $strKey

$strDict[$Y][$dictItem] = $strItem

EndIf

Next

Next

; erase the contents of the dictionary object

$objDict.RemoveAll

; repopulate the dictionary with the sorted information

For $X = 0 to ($Z - 1)

$objDict.Add($strDict[$X][$dictKey], $strDict[$X][$dictItem])

Next

EndIf

EndFunc

Func WriteFileList()

FileWrite($outFile, $var & @CRLF & "FOLDERS:" & @CRLF & @CRLF)

For $i = 1 To UBound($FolderArray)-1

FileWrite($outFile, $FolderArray[$i] & @CRLF)

Next

EndFunc

Any help is greatly appreciated.

vatobeto.

Duh! An empty dictionary is bound to cause some problems:

$oDictionary = _InitDictionary()

SortDictionary($oDictionary, $dictKey)

$kArray = $oDictionary.keys

_ArrayDisplay($kArray)

Nevermind...

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