david1337

Create GUI buttons from ListToArray result

3 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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

 

1 person likes this

Share this post


Link to post
Share on other sites

InunoTaishou,

Exactly what I was looking for! Thank you so much, I will learn from your code now :-)

 

 

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