Sign in to follow this  
Followers 0
goodbyeplanet

Subscript used with non-Array variable

5 posts in this topic

i run the code below inside a fucntion and it keeps giving me the error "Subscript used with non-Array variable". the arrow points at the square brackets with [0]. where could i be going wrong. thanks for your help.

$FileDate = FileGetTime($file, 0, 0)
            $ymd = $FileDate[0] & "/" & $FileDate[1] & "/" & $FileDate[2]
            MsgBox(4096, "File:", $file)
            msgbox(0,"FILE CREATED ON", $ymd)

Share this post


Link to post
Share on other sites



i run the code below inside a fucntion and it keeps giving me the error "Subscript used with non-Array variable". the arrow points at the square brackets with [0]. where could i be going wrong. thanks for your help.

$FileDate = FileGetTime($file, 0, 0)
            $ymd = $FileDate[0] & "/" & $FileDate[1] & "/" & $FileDate[2]
            MsgBox(4096, "File:", $file)
            msgbox(0,"FILE CREATED ON", $ymd)

Is the variable $file a full path or just a file name?

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites

Is the variable $file a full path or just a file name?

below is my full function

Func ScanFolder($Folder)
    Local $Search
    Local $File
    Local $Attrib
    Local $Path
    
  
    $Search = FileFindFirstFile($Folder & "\*.*")
 
    While 1
        If $Search = -1 Then
            ExitLoop
        EndIf

        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        $Path = $Folder & "\" & $File
        $Attrib = FileGetAttrib($Path)
                
        msgbox(0,"", $Path)      
        msgbox(0,"", $Attrib)        
        If StringInStr($Attrib,"D") Then
            ScanFolder($Path)
            
        Else
            $FileDate = FileGetTime($file, 0, 0)
            $ymd = $FileDate[0] & "/" & $FileDate[1] & "/" & $FileDate[2]
            MsgBox(4096, "File:", $file)
            msgbox(0,"FILE CREATED ON", $ymd)   
            LogFile($Path)
        EndIf
        
    WEnd
 
    FileClose($Search)
EndFunc

Share this post


Link to post
Share on other sites

Try this:

Func ScanFolder($Folder)
    Local $Search
    Local $File
    Local $Attrib
    Local $Path
    
  
    $Search = FileFindFirstFile($Folder & "\*.*")
 
    While 1
        If $Search = -1 Then
            ExitLoop
        EndIf

        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        $Path = $Folder & "\" & $File
        $Attrib = FileGetAttrib($Path)
                
        msgbox(0,"", $Path)      
        msgbox(0,"", $Attrib)        
        If StringInStr($Attrib,"D") Then
            ScanFolder($Path)
            
        Else
            $FileDate = FileGetTime($Path, 0, 0) ;<<<<***************** Changed it to $Path here
            $ymd = $FileDate[0] & "/" & $FileDate[1] & "/" & $FileDate[2]
            MsgBox(4096, "File:", $file)
            msgbox(0,"FILE CREATED ON", $ymd)   
            LogFile($Path)
        EndIf
        
    WEnd
 
    FileClose($Search)
EndFunc

FileGetTime () requires a full path, not just a file name.

(This is untested)


Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Share this post


Link to post
Share on other sites

Try this:

FileGetTime () requires a full path, not just a file name.

(This is untested)

you are just amazing....your suggestion worked like charm, since morning i have been trying to figure out the problem without succes but your suggestion has indeed helped...thanks again and many blessings.....

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