Jump to content
faustf

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

Recommended Posts

faustf

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

 

Share this post


Link to post
Share on other sites
Andreik

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

Share this post


Link to post
Share on other sites
Zedna

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

 

Share this post


Link to post
Share on other sites
faustf

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

Share this post


Link to post
Share on other sites
faustf

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

 

Share this post


Link to post
Share on other sites
Andreik

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

Share this post


Link to post
Share on other sites
faustf

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

 

  • Like 1

Share this post


Link to post
Share on other sites
Earthshine

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

 

Share this post


Link to post
Share on other sites
JLogan3o13

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
  • Like 1

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
faustf

ok i will do :)  thankz again

 

Share this post


Link to post
Share on other sites
Andreik

How could you call this an UDF when you comment the part of the function that tells you're not doing it right? :blink:


When the words fail... music speaks

Share this post


Link to post
Share on other sites
faustf

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

 

Share this post


Link to post
Share on other sites
JLogan3o13

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.


√-1 2^3 ∑ π, and it was delicious!

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

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.