Docfxit 7 Posted October 8, 2007 I have been trying to create a routine to select a file from a list of files. I can't get it to return the selected file name to AutoIt. expandcollapse popup; includes #include <GuiConstants.au3> #include <GuiEdit.au3> #include <file.au3> AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{ESC}", "Set_Exit") DIM $FileList ; create the GUI. GUICreate("File List/View Demo", 614, 370) ; set the font for the GUI GUISetFont(9, 400, -1, "MS Sans Serif") ; create buttons. $Status = GUICtrlCreateLabel("", 30, 120, 200, 20, BitOR($SS_SUNKEN, $SS_CENTER)) $btnList = GUICtrlCreateButton("&Select A File", 10, 330, 75, 25) $listbox = GUICtrlCreateList("", 10, 10, 150, 330) ; create the right edit. $myedit = GUICtrlCreateEdit($FileList, 175, 10, 220, 345, $ES_AUTOVSCROLL + $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL) ; set the edit colors. GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetColor(-1, 0x000000) ; set focus to the edit. GUICtrlSetState($listbox, $GUI_FOCUS) GUISetState() Get_Files() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btnList $a_Sel = _GUICtrlEditGetSel ($myedit) If ($a_Sel == $EC_ERR) Then GUICtrlSetData($Status, "Error getting sel positions") ElseIf (IsArray($a_Sel)) Then $FileSelected = StringMid(GUICtrlRead($myedit), $a_Sel[1] + 1, ($a_Sel[2] - $a_Sel[1]) + 1) $FileSelectedT = StringStripWS($FileSelected, 2) GUICtrlSetData($Status, $FileSelectedT) Else GUICtrlSetData($Status, "") EndIf GUIDelete() ExitLoop EndSelect WEnd Func Get_Files() $FileList = _FileListToArray ("C:\Program Files\QuickBooks Pro 2004", "*.iif", 1) ; list files to an array. If (Not IsArray($FileList)) Or (@error = 1) Then MsgBox(262208, "Folder Error", "No Files\Folders Found. ", 5) Return EndIf GUICtrlSetData($listbox, "") ; set list to empty. For $x = 1 To $FileList[0] ; for loop to place the files in the list. GUICtrlSetData($listbox, (StringTrimRight($FileList[$x], 4)) & "|", 1) ; string trim the last 4 characters ( .iif ) Next EndFunc Func Set_Exit () Exit EndFunc ;==>Set_Exit Could someone please help me figure out what I am doing wrong? Thank you, Docfxit Share this post Link to post Share on other sites
Valuater 130 Posted October 8, 2007 Try this.... NOT TESTED expandcollapse popup; includes #include <GuiConstants.au3> #include <GuiEdit.au3> #include <file.au3> #include <GUIListBox.au3> ; added************************* AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{ESC}", "Set_Exit") DIM $FileList ; create the GUI. GUICreate("File List/View Demo", 614, 370) ; set the font for the GUI GUISetFont(9, 400, -1, "MS Sans Serif") ; create buttons. $Status = GUICtrlCreateLabel("", 30, 120, 200, 20, BitOR($SS_SUNKEN, $SS_CENTER)) $btnList = GUICtrlCreateButton("&Select A File", 10, 330, 75, 25) $listbox = GUICtrlCreateList("", 10, 10, 150, 330) ; create the right edit. $myedit = GUICtrlCreateEdit($FileList, 175, 10, 220, 345, $ES_AUTOVSCROLL + $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL) ; set the edit colors. GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetColor(-1, 0x000000) ; set focus to the edit. GUICtrlSetState($listbox, $GUI_FOCUS) GUISetState() Get_Files() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btnList $a_Sel = _GUICtrlEditGetSel ($myedit) If ($a_Sel == $EC_ERR) Then GUICtrlSetData($Status, "Error getting sel positions") ElseIf (IsArray($a_Sel)) Then $FileSelected = StringMid(GUICtrlRead($myedit), $a_Sel[1] + 1, ($a_Sel[2] - $a_Sel[1]) + 1) $FileSelectedT = StringStripWS($FileSelected, 2) GUICtrlSetData($Status, $FileSelectedT) Else GUICtrlSetData($Status, "") EndIf GUIDelete() ExitLoop EndSelect WEnd Func Get_Files() $FileList = _FileListToArray ("C:\Program Files\QuickBooks Pro 2004", "*.iif", 1) ; list files to an array. If (Not IsArray($FileList)) Or (@error = 1) Then MsgBox(262208, "Folder Error", "No Files\Folders Found. ", 5) Return EndIf GUICtrlSetData($listbox, "") ; set list to empty. For $x = 1 To $FileList[0] ; for loop to place the files in the list. ;GUICtrlSetData($listbox, (StringTrimRight($FileList[$x], 4)) & "|", 1) ; string trim the last 4 characters ( .iif ) _GUICtrlListBox_AddString ($listbox, (StringTrimRight($FileList[$x], 4))) ; string trim the last 4 characters ( .iif ) Next EndFunc Func Set_Exit () Exit EndFunc ;==>Set_Exit 8) Share this post Link to post Share on other sites
Docfxit 7 Posted October 8, 2007 (edited) Thank you for the suggestion. I added some notes below to show what is in the fields... Try this.... NOT TESTED expandcollapse popup; includes #include <GuiConstants.au3> #include <GuiEdit.au3> #include <file.au3> #include <GUIListBox.au3> ; added************************* AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{ESC}", "Set_Exit") DIM $FileList ; create the GUI. GUICreate("File List/View Demo", 614, 370) ; set the font for the GUI GUISetFont(9, 400, -1, "MS Sans Serif") ; create buttons. $Status = GUICtrlCreateLabel("", 30, 120, 200, 20, BitOR($SS_SUNKEN, $SS_CENTER)) $btnList = GUICtrlCreateButton("&Select A File", 10, 330, 75, 25) $listbox = GUICtrlCreateList("", 10, 10, 150, 330) ; create the right edit. $myedit = GUICtrlCreateEdit($FileList, 175, 10, 220, 345, $ES_AUTOVSCROLL + $ES_READONLY + $ES_MULTILINE + $WS_VSCROLL) ; set the edit colors. GUICtrlSetBkColor(-1, 0xFFFFFF) GUICtrlSetColor(-1, 0x000000) ; set focus to the edit. GUICtrlSetState($listbox, $GUI_FOCUS) GUISetState() Get_Files() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $btnList $a_Sel = _GUICtrlEditGetSel ($myedit) If ($a_Sel == $EC_ERR) Then GUICtrlSetData($Status, "Error getting sel positions") ElseIf (IsArray($a_Sel)) Then $FileSelected = StringMid(GUICtrlRead($myedit), $a_Sel[1] + 1, ($a_Sel[2] - $a_Sel[1]) + 1) ;Notes: When I run this: ; $FileSelected = Blank ; $a_Sel[1] = 0 ; $a_Sel[2] = 0 $FileSelectedT = StringStripWS($FileSelected, 2) GUICtrlSetData($Status, $FileSelectedT) Else GUICtrlSetData($Status, "") EndIf GUIDelete() ExitLoop EndSelect WEnd Func Get_Files() $FileList = _FileListToArray ("C:\Program Files\QuickBooks Pro 2004", "*.iif", 1) ; list files to an array. If (Not IsArray($FileList)) Or (@error = 1) Then MsgBox(262208, "Folder Error", "No Files\Folders Found. ", 5) Return EndIf GUICtrlSetData($listbox, "") ; set list to empty. For $x = 1 To $FileList[0] ; for loop to place the files in the list. ;GUICtrlSetData($listbox, (StringTrimRight($FileList[$x], 4)) & "|", 1) ; string trim the last 4 characters ( .iif ) _GUICtrlListBox_AddString ($listbox, (StringTrimRight($FileList[$x], 4))) ; string trim the last 4 characters ( .iif ) ; Notes: The files do show in the box. The file I select doesn't come back into the script. Next EndFunc Func Set_Exit () Exit EndFunc ;==>Set_Exit 8) Thank you, Docfxit Edited October 8, 2007 by docfxit Share this post Link to post Share on other sites
Docfxit 7 Posted October 8, 2007 Thank you for your help. I have figured it out. This is the working code: expandcollapse popup; Select a file from a list of files ; #include <GuiConstants.au3> #include <GuiEdit.au3> #include <GuiList.au3> #include <file.au3> AutoItSetOption("TrayIconDebug", 1) ;0-off ; Set so that tray displays current line number HotKeySet("{ESC}", "Set_Exit") GUICreate("File List", 220, 370) GUISetFont(9, 400, -1, "MS Sans Serif") $listbox = GUICtrlCreateList("", 10, 10, 200, 330) Get_Files() GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = $listbox $FileSelected = _GUICtrlListGetText($listbox, _GUICtrlListSelectedIndex($listbox)) If ($FileSelected == $LB_ERR) Then MsgBox(16, "Error", "Unknown error from _GUICtrlListGetText") Else MsgBox(4096, "Test", "File Selected - " & $FileSelected) ExitLoop EndIf EndSelect WEnd Func Get_Files() $FileList = _FileListToArray("C:\Program Files\QuickBooks Pro 2004", "*.iif", 1) ; list files to an array. If (Not IsArray($FileList)) Or (@error = 1) Then MsgBox(262208, "Folder Error", "No Files\Folders Found. ", 5) Return EndIf GUICtrlSetData($listbox, "") ; set list to empty. For $x = 1 To $FileList[0] ; for loop to place the files in the list. GUICtrlSetData($listbox, (StringTrimRight($FileList[$x], 4)) & "|", 1) ; string trim the last 4 characters ( .iif ) Next EndFunc ;==>Get_Files Func Set_Exit() Exit EndFunc ;==>Set_Exit Thank you, Docfxit Share this post Link to post Share on other sites