Jump to content

Array problem


Recommended Posts

Hey guys, i've still been having problems with arrays. And i'm wondering if you guys can point out what i'm doing wrong here. What i'm trying to do is list all the files from MyDocuments into a list view in a GUI, heres what i've thought of so far:

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <File.au3>

GUICreate("", 200, 200)

$List_View = GUICtrlCreateListView("", 1, 1, 200, 200)

$Array = _FileListToArray(@MyDocumentsDir, "Text Files, (*.txt)")

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $List_View
            For $i = 1 To $Array
                _GUICtrlListView_AddArray($List_View, $Array_To_List_View)
            Next
    EndSelect
    WEnd
Thanks, Clipper34.

Link to comment
Share on other sites

  • Moderators

It's _GUICtrlListView_AddArray, not _GUICtrlListView_AddArrayElements :P

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $List_View
            _GUICtrlListView_AddArray($List_View, $Array)
    EndSelect
    WEnd
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

  • Moderators

Actually, it accepts a 2 dimensional array, not just a one, so I was wrong as well. Your FileListToArray was incorrect as well, it seems you were trying to use it like FileOpenDialog or something.

Take note on the changes, reading the directory into an array, changing the 1 dimensional array it returns into a 2 dimensional array, then creating a column for the listview to actually put the data in, then adding the array:

#include <GuiConstantsEx.au3>
#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <File.au3>

$h_gui = GUICreate("", 200, 200)

$List_View = _GUICtrlListView_Create($h_gui, "", 1, 1, 200, 200)
_GUICtrlListView_AddColumn($List_View, "Files", 100)

$Array = _FileListToArray(@MyDocumentsDir, "*.*")
Dim $a_lv_array[$Array[0]][1]
For $i = 1 To $Array[0]
    $a_lv_array[$i - 1][0] = $Array[$i]
Next

_ArrayDisplay($a_lv_array)
_GUICtrlListView_AddArray($List_View, $a_lv_array)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
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

CODE
#include <array.au3>

#include <file.au3>

$a_FileList=_FileListToArray(@MyDocumentsDir, "*.txt")

If @error=1 Then

MsgBox (0,"","No files\folders Found.")

Exit

EndIf

_ArrayDisplay($a_FileList, "$a_FileList")

Contact via MSN: [email=terarink_msn@hotmail.com]terarink_msn@hotmail.com[/email], yahoo: terarink_yah

Link to comment
Share on other sites

Thanks SmOke N, and TerarinKerowyn. I have another question, when ever i try to put a filter in the _FileListToArray i keep getting an error. But when i put "*.*" in the filter it accepts it and works. Thanks, Clipper34.

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