Sign in to follow this  
Followers 0
Simmy

Selecting an entry from a combo box and firing it off.

4 posts in this topic

#1 ·  Posted (edited)

Hi guys hope you are all well.

I have the following script that works nearly as I would like it, but not quite.

What it does is read a list of .exe files in subfolders.

It does this by using the dir command with a /B and /S switch and writes to a text file the file names.

That file is then read one line at a time and fed into the combo box with GUICtrlSetData.

What I would like to do now is to:

a) When I click on one of the entries in the list, I want to fire off the exe that has been selected.

:huh2: If I close that particular exe selected, I want the original form to remain there so I can select another in the list.

Any help greatly appreciated.

#include <Array.au3>
#include <File.au3>
#include <GUIComboBox.au3>
#include <GUIConstantsEx.au3>

_Main()


Func _Main()
    Local $hCombo, $iCombo

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Output the exe list to a text file. Skip the echo is on line, by using skip=1.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    RunWait(@ComSpec & ' /c for /f "tokens=* delims=\ skip=1" %a in (''dir apps /B /S .exe'') do @echo %a >> grplist.txt','',@SW_HIDE)

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Create a form.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        GUICreate('Executables', 500, 300)

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Create a combo to hold the data.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        ;$iCombo = GUICtrlCreateCombo("Select A Folder", 30, 75, 220, 200)
        ;Don't put a title in as this will create an entry in the combo box.
        $iCombo = GUICtrlCreateCombo("", 30, 75, 220, 200)
        $hCombo = GUICtrlGetHandle(-1)



    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Open the file in order to read it.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        $FileOpen = FileOpen('grplist.txt', 0)

        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        ;Add error-handling for file.
        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

            If $FileOpen = -1 Then
                MsgBox(0, "Error", "Unable to open file.")
                Exit
            EndIf


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Set the data of the combo by looping through the file.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        While 1
            $line = FileReadLine($FileOpen)
            If $line = "" Then ExitLoop
            If @error = -1 Then ExitLoop
            GUICtrlSetData($iCombo,$line)
        Wend
;_FileReadToArray

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Set the default visible entry in the combobox with this function.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    _GUICtrlComboBox_SetEditText($hCombo, "Select A Folder")

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Close the file to free resources.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        FileClose($FileOpen)

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Show the form since forms are hidden by default.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        GUISetState(@SW_SHOW)

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;Keep the form open until you close it.
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

EndFunc   ;==>_Main

post-65297-0-94091500-1308203418_thumb.j

Edited by Simmy

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If you using Melba's whole thing will become so much easier. :huh2:

You want to create a button control that user can click to fire a selected program by reading combobox with GUICtrlRead. Then, monitor your process with ProcessExists function.

Edited by Joon

Share this post


Link to post
Share on other sites

If you using Melba's whole thing will become so much easier. :huh2:

You want to create a button control that user can click to fire a selected program by reading combobox with GUICtrlRead. Then, monitor your process with ProcessExists function.

In addition, use Run() to get the PID to monitor or just use RunWait() to let the app run until it's done or until you close out of it.

Also, for your function:

While 1

$line = FileReadLine($FileOpen)

If $line = "" Then ExitLoop

If @error = -1 Then ExitLoop

GUICtrlSetData($iCombo,$line)

Wend

You might want to switch the "If $line" and "If @error" lines...I don't think If @error will work as intended in its current position but I could be wrong!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi guys, thanks so much for your help.

I did try Joon to use Melbas _RecFileListToArray.au3, but because Im a newbie or just plain thick, I just could not get it to work.

I could not work out the right parameters to use with it. Should I post another question about how to use that?

Edited by Simmy

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