Jump to content

Create GUI buttons from ListToArray result


david1337
 Share

Recommended Posts

Hey guys

I hope you can get me in the right direction with this one:

 

It's pretty easy to get a list with a specific filetype, and show it with _ArrayDisplay

#include <File.au3>

Local $aFileList = _FileListToArray("C:\Test\", "*.txt")

_ArrayDisplay($aFileList, "Available text files")

But what if I want to create a GUI with a button for every available txt file, and name each button after the txt file?

Let's say I have 3 txt files in C:\Test\

file1.txt
file2.txt
file3.txt

Should end up with a GUI with 3 buttons lined up vertically:

[ file1 ]
[ file2 ]
[ file3 ]

 

I hope it makes sense :-)

Edited by david1337
Link to comment
Share on other sites

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

Global $aButtonIds = _FileListToArray("C:\test\", "*.*", $FLTA_FILES)
Global $hGui = GUICreate("Edit Get Text", 400, 300)
Global $aButtons[_ArrayDelete($aButtonIds, 0)]

For $i = 0 to UBound($aButtonIds) - 1
    $aButtonIds[$i] = GUICtrlCreateButton($aButtonIds[$i], 10, 10 + ($i * 30), 100, 20)
Next

GUISetState(@SW_SHOW, $hGui)

While (True)
    Local $iMsg = GUIGetMsg()
    Switch ($iMsg)
        Case $GUI_EVENT_CLOSE
            Exit 0
        Case Else
            For $i = 0 to UBound($aButtonIds) - 1
                If ($iMsg = $aButtonIds[$i]) Then
                    MsgBox("", "", "Button " & GUICtrlRead($aButtonIds[$i]) & " pressed")
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

 

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