Jump to content

Subscript used on non-accessible variable.: why???


Recommended Posts

hi guys  i have  a script , it  give me  this Subscript used on non-accessible variable.: , but i dont understund  why

 

#AutoIt3Wrapper_Compression=3
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include 'BackupFiles.au3'
#include <WinAPIFiles.au3>
#include <File.au3>



_FindOldestFolder("C:\Users\SviluppoGest\Desktop\da-cancellare")



Func _FindOldestFolder($Path)

    Local $FileList = _FileListToArray($Path, "*.*", 2)
    If @error = 1 Then
        MsgBox(0, "", "No Folders Found.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox(0, "", "No Files Found.")
        Exit
    EndIf
    Local $dLDateDay = _NowCalc()
    MsgBox(0, '', $dLDateDay)


    For $i = 0 To UBound($FileList) - 1

        Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0)
        _ArrayDisplay($aDateFolder)




        MsgBox(0, '', $aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5])
    Next


EndFunc   ;==>_FindOldestFolder

 

Link to comment
Share on other sites

Because $FileList index 0 contains the number of indices in your array and later you start a loop from index 0 and $Path & "\" & $FileList[$i] is not a valid file/directory and your function set error flag. This is why you should check @error marco after you call a function.

When the words fail... music speaks.

Link to comment
Share on other sites

And here is the way how to check for @error after FileGetTime()

#AutoIt3Wrapper_Compression=3
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include 'BackupFiles.au3'
#include <WinAPIFiles.au3>
#include <File.au3>

_FindOldestFolder("C:\Users\SviluppoGest\Desktop\da-cancellare")

Func _FindOldestFolder($Path)

    Local $FileList = _FileListToArray($Path, "*.*", 2)
    If @error = 1 Then
        MsgBox(0, "", "No Folders Found.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox(0, "", "No Files Found.")
        Exit
    EndIf
    Local $dLDateDay = _NowCalc()
    MsgBox(0, '', $dLDateDay)

    For $i = 0 To UBound($FileList) - 1

        Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0)
        If @error Then
            MsgBox(0, "FileGetTime Error", $Path & "\" & $FileList[$i])
        Else
            _ArrayDisplay($aDateFolder)
            MsgBox(0, '', $aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5])
        EndIf
    Next

EndFunc   ;==>_FindOldestFolder

 

Link to comment
Share on other sites

but array display  don't  give me at  row[0] the  indices , but  give me  the year 2018 o_O

and if  i substitute

MsgBox(0, '', $aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & 
$aDateFolder[5])

with this

MsgBox(0, '', $aDateFolder[1] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5])

i have  the same error

 

Edited by faustf
Link to comment
Share on other sites

questions i modify the script in this mode  and  i work , but  not understund  why work and  i think is  a bug  of  autoit

Func _FindOldestFolder($Path)

    Local $FileList = _FileListToArray($Path, "*.*", 2)
    If @error = 1 Then
        MsgBox(0, "", "No Folders Found.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox(0, "", "No Files Found.")
        Exit
    EndIf
    Local $dLDateDay = _NowCalc()
    MsgBox(0, '', $dLDateDay)


    For $i = 0 To UBound($FileList) - 1

        Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0)
          If @error Then
            MsgBox(0, "FileGetTime Error", $Path & "\" & $FileList[$i])
        Else
        _ArrayDisplay($aDateFolder)


        ;MsgBox(0, '',$aDateFolder[$i])

        MsgBox(0, '', $aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5])
        EndIf
    Next


EndFunc   ;==>_FindOldestFolder

when execute  them  , the program answer me  with  msgbox  error and  condition if @error then is  verifyed , but in the same time go in else and  execute also else , but   not  give me a error o_O  , anyone  can  explain me  ?? thankz

 

Link to comment
Share on other sites

I already pointed your mistake but seems you don't pay attention. _FileListToArray() always return an array, 0-based indexed, where index 0 contains the number of files (also the number of indices) in your array. And then you have this loop

For $i = 0 To UBound($FileList) - 1
    Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0)
    ....
Next

where you start your iteration from index 0 where you have the number of files in your array instead of the name of a valid file/directory. This is the reason why your FileGetTime() function returns nothing at first iteration and an error is thrown. To fix your problem just start your loop at index 1, something like:

For $i = 1 To $FileList[0]
    ...
Next

 

When the words fail... music speaks.

Link to comment
Share on other sites

hi  i have created a udf , i hope will be helpful at the comunity , best thankz at all for help

and ofcourse if someone want modify , is welcome 

:)

; #FUNCTION# ====================================================================================================================
; Name ..........: _FindOldestFolder
; Description ...: _FindOldestFolder udf functions find a oldest or newer folder inside a folder
; Syntax ........: _FindOldestFolder($Path, $old_new = 0)
; Parameters ....: $Path        - dirctory you wish find 
;                  $old_new     - choice if a program must find oldest "0" or yanger "1" folder ,default oldest
; Return values .:
; Author ........: Faustf
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================


Func _FindOldestFolder($Path, $old_new = 0)


    If $old_new = Default Then $old_new = 0
    Local $FileList = _FileListToArray($Path, "*.*", 2)
    If @error = 1 Then
        MsgBox(0, "", "No Folders Found.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox(0, "", "No Files Found.")
        Exit
    EndIf

    Local $aLDateDiff[($FileList[0] + 1)]

    For $i = 0 To UBound($FileList) - 1
        Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0)
        If @error Then
            ;MsgBox(0, "FileGetTime Error", $Path & "\" & $FileList[$i])
        Else
            Local $dLOldDate = ($aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5])
            $aLDateDiff[$i] = _DateDiff("s", $dLOldDate, _NowCalc())
        EndIf
    Next
    If $old_new = 0 Then
        Return $FileList[_ArrayMaxIndex($aLDateDiff)]
    Else
        Return $FileList[_ArrayMinIndex($aLDateDiff)]
    EndIf

EndFunc   ;==>_FindOldestFolder

 

Link to comment
Share on other sites

sweet. You could probably start a new thread in the AutoIT Example Forum. My point being, people are probably going to not associate this thread title with a UDF that finds the oldest folder. I will test it. Nice work BTW.

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Link to comment
Share on other sites

  • Moderators

Agreed. @faustf if the script actually works, it is probably better to add it to the Examples forum (more of an addition to the snippets thread than a full UDF IMO), rather than posting it in a topic where it looks like you did not know what you were doing. 

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

yea have right , sorry i copyed a udf wrong o:)

; #FUNCTION# ====================================================================================================================
; Name ..........: _FindOldestFolder
; Description ...: _FindOldestFolder udf functions find a oldest or newer folder inside a folder
; Syntax ........: _FindOldestFolder($Path, $old_new = 0)
; Parameters ....: $Path        - dirctory you wish find
;                  $old_new     - choice if a program must find oldest "0" or yanger "1" folder ,default oldest
; Return values .:
; Author ........: Faustf
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================


Func _FindOldestFolder($Path, $old_new = 0)

    If $old_new = Default Then $old_new = 0
    Local $FileList = _FileListToArray($Path, "*.*", 2)
    If @error = 1 Then
        MsgBox(0, "", "No Folders Found.")
        Exit
    EndIf
    If @error = 4 Then
        MsgBox(0, "", "No Files Found.")
        Exit
    EndIf

    Local $aLDateDiff[($FileList[0] + 1)]

    For $i = 1 To UBound($FileList) - 1
        Local $aDateFolder = FileGetTime($Path & "\" & $FileList[$i], 1, 0)
        If @error Then
            ;MsgBox(0, "FileGetTime Error", $Path & "\" & $FileList[$i])
            Return 0
        Else
            Local $dLOldDate = ($aDateFolder[0] & "/" & $aDateFolder[1] & "/" & $aDateFolder[2] & " " & $aDateFolder[3] & ":" & $aDateFolder[4] & ":" & $aDateFolder[5])
            $aLDateDiff[$i] = _DateDiff("s", $dLOldDate, _NowCalc())
        EndIf
    Next
    If $old_new = 0 Then
        Return $FileList[_ArrayMaxIndex($aLDateDiff)]
    Else
        Return $FileList[_ArrayMinIndex($aLDateDiff)]
    EndIf

EndFunc   ;==>_FindOldestFolder

 

Link to comment
Share on other sites

  • Moderators

Still think this is more a snippet than a UDF, and if you do post in Examples, don't be surprised if you receive some critique.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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