Jump to content

My first time using arrays


NELyon
 Share

Recommended Posts

I'm working on a program that will let me copy files to and from my sd card. I got it to list the files perfectly with "_FileListToArray" and they displayed perfectly. So i tried adding a copy function. To me, it looks like it should work fine, but if i press copy, i get the error message "Array variable has incorrect number of subscripts or subscript dimension range exceeded."

Heres the code:

#include <GUIConstants.au3>
#Include <File.au3>
; == GUI generated with Koda ==
$Form1 = GUICreate("AForm1", 669, 391, 192, 125)
$List1 = GUICtrlCreateList("", 0, 0, 249, 383)
$List2 = GUICtrlCreateList("", 416, 0, 249, 383)
$Button1 = GUICtrlCreateButton("Choose Removable Folder", 256, 8, 145, 33, 0)
$Button2 = GUICtrlCreateButton("Choose Source Folder", 256, 320, 153, 41, 0)
$Button3 = GUICtrlCreateButton("Copy", 256, 250, 153, 41, 0)
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button1
        $Folder = FileSelectFolder("Select", "")
        $arr = _FileListToArray($Folder)
        for $i = 1 to $arr[0] step +1
        GUICtrlSetData($List1, $arr[$i])    
    Next
Case $msg = $Button2
    $Folder2 = FileSelectFolder("Slelect Folder", "")
    $ar = _FileListToArray($Folder)
    for $ii = 1 to $ar[0] step +1
        GUICtrlSetData($List2, $arr[$ii])
    Next
Case $msg = $Button3 ;the problem is right down here
    FileCopy(GUICtrlread($List2), GUICtrlread($List1))
    GUICtrlSetData($List1, $arr[$i])
    EndSelect
WEnd
Exit

Can anyone help me out here?

Link to comment
Share on other sites

  • Moderators

Although _FileListToArray() lists all of the files for that directory, it doesn't list the rest of the path.

Have you tried to do:

GUICtrlSetData($List2, $PathToDirectory & '\' & $arr[$ii])
?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Another problem is you're not accounting for an empty folder (therefore an empty array) when you create your list, or if cancel is hit when selecting a folder. For example, try this for your $Button1

Case $msg = $Button1
            $Folder = FileSelectFolder("Select", "")
            If Not @error Then
                $arr = _FileListToArray($Folder)
                If IsArray($arr) Then
                    For $i = 1 To $arr[0] Step + 1
                        GUICtrlSetData($List1, $arr[$i])
                    Next
                EndIf
            EndIf

edit - sp

Edited by xcal
Link to comment
Share on other sites

I tried this, and it worked the first time i tried it, then it stopped working. Doesen't throw any error, just won't copy.

#include <GUIConstants.au3>
#Include <File.au3>
; == GUI generated with Koda ==
$Form1 = GUICreate("AForm1", 669, 391, 192, 125)
$List1 = GUICtrlCreateList("", 0, 0, 249, 383)
$List2 = GUICtrlCreateList("", 416, 0, 249, 383)
$Button1 = GUICtrlCreateButton("Choose Removable Folder", 256, 8, 145, 33, 0)
$Button2 = GUICtrlCreateButton("Choose Source Folder", 256, 320, 153, 41, 0)
$Button3 = GUICtrlCreateButton("Copy", 256, 250, 153, 41, 0)
GUISetState(@SW_SHOW)
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button1
        $Folder = FileSelectFolder("Select", "")
        $arr = _FileListToArray($Folder)
        for $i = 1 to $arr[0] step +1
        GUICtrlSetData($List1, $arr[$i])
    Next
Case $msg = $Button2
    $Folder2 = FileSelectFolder("Slelect Folder", "")
    $ar = _FileListToArray($Folder2)
    for $ii = 1 to $ar[0] step +1
        GUICtrlSetData($List2, $ar[$ii])
    Next
Case $msg = $Button3
    FileCopy(GUICtrlRead($List2), GUICtrlRead($List1) & "\")
    EndSelect
WEnd
Exit
Link to comment
Share on other sites

  • Moderators

This line doesn't strike you as odd... see anything missing :) ?

FileCopy(GUICtrlRead($List2), GUICtrlRead($List1) & "\")

Edit:

And you've still not done what I originally told you to do.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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