Jump to content

Subscript used in non-array variable


imani
 Share

Recommended Posts

Can any one correct this error.

The error in this code is

Subscript used in non-array variable

;;#include<G:\For Technodigits\AutoIT Lab\allscripts.au3>
$folder = InputBox("Enter path of folder","Enter path of folder to list folders",@DesktopDir)
lister()
Func lister($folder = "")
Local $a,$b
$folder = $folder&"\"
$a = new($folder)
if @error =1  Then
    MsgBox(0,'','Some error occured')
    Else
While $a[0] > 0
    for $y =1 to $a[0] Step 1
        MsgBox(0,'',$folder&$a[$y])
    Next    
WEnd
EndIf
EndFunc
Func new($folder)
    Local $array
$array=_FileListToArray($folder,"*",2)
    If @Error=1 Then
    MsgBox (0,"","No Files\Folders Found.")
    Exit
EndIf
Return $array
EndFunc

Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $sFile, $asFileList[1]
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If (StringInStr($sFilter, "\")) Or (StringInStr($sFilter, "/")) Or (StringInStr($sFilter, ":")) Or (StringInStr($sFilter, ">")) Or (StringInStr($sFilter, "<")) Or (StringInStr($sFilter, "|")) Or (StringStripWS($sFilter, 8) = "") Then Return SetError(2, 2, "")
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
    $hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
    If $hSearch = -1 Then Return SetError(4, 4, "")
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then
            SetError(0)
            ExitLoop
        EndIf
        If $iFlag = 1 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop
        If $iFlag = 2 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
        ReDim $asFileList[UBound($asFileList) + 1]
        $asFileList[0] = $asFileList[0] + 1
        $asFileList[UBound($asFileList) - 1] = $sFile
    WEnd
    FileClose($hSearch)
    Return $asFileList
EndFunc
Link to comment
Share on other sites

you haven't declared $a as an array but you are using it like that

Local $a[1] or Dim $a[1]

His new() function appears to return an array into $a.

We need the full error text, which will have line number and will show the failed line.

:)

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...