l3ill Posted December 2, 2013 Share Posted December 2, 2013 Hi All, I have been playing with this little problem for about a week now and just cant get it to work. I have tried literally 100 different variations and combed the forums for solutions....no luck. It is actually a very basic listView GUI that lists all files in the Directory it is placed (originally a snippet browser for .au3 files) with an edit box on the bottom to preview the selected txt / au3 file. The preview function does not work. The RecFileListToArray (thanks M23) ! does an excellent job of giving me a list of full paths. A selected path is sent to the preview function which should show up in the edit box. If I insert the full path (static) as a variable it works fine ( see commented out full path for testing ). Any help with this would be very cool... expandcollapse popup#include <Array.au3> #include <File.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <GUIConstantsEx.au3> #include <Constants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ListviewConstants.au3> #include <GuiListView.au3> #include "C:\Users\Badass\Desktop\RecFileListToArray\RecFileListToArray.au3" Local $showText = "" Local $sFolder = @ScriptDir ; works as browser in any folder you put the script in $Form1 = GUICreate("SnippetBrowser", 810, 680, 246, 140, $WS_SIZEBOX, $WS_EX_ACCEPTFILES) $Input1 = GUICtrlCreateInput("Dummy", 10, 16, 180, 21) $sBlistView = GUICtrlCreateListView("Path", 10, 45, 790, 353, BitOR($LVS_SINGLESEL, $LVS_SHOWSELALWAYS)) _GUICtrlListView_SetColumnWidth($sBlistView, 0, 300) $getFiles = GUICtrlCreateButton("Get Files", 210, 14, 81, 25) GUICtrlSetState($getFiles, $GUI_DEFBUTTON) $ClearAll = GUICtrlCreateButton("Clear All", 310, 14, 81, 25) $Dummy = GUICtrlCreateButton("Dummy", 410, 14, 81, 25) $showSelected = GUICtrlCreateButton("Preview", 460, 405, 91, 25) $label1 = GUICtrlCreateLabel($sFolder, 510, 20, 400, 25) GUICtrlSetData($label1, $sFolder) $openSelected = GUICtrlCreateButton("Open in SciTE", 360, 405, 91, 25) $hEdit = GUICtrlCreateEdit("", 10, 440, 790, 235) GUISetState(@SW_SHOW, $Form1) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $getFiles _getFiles() Case $openSelected _openSelected() Case $ClearAll _GUICtrlListView_DeleteAllItems($sBlistView) Case $showSelected _showSelected() EndSwitch WEnd Func _getFiles() Global $FileList_A = _RecFileListToArray(@ScriptDir, "*", 1, 0, 0, 2) $rows = UBound($FileList_A) For $i = 0 To $rows - 1 _GUICtrlListView_AddItem($sBlistView, $FileList_A[$i] & @LF) ConsoleWrite("$FileList_A[$i]: " & $FileList_A[$i] & @CR) Next EndFunc ;==>_getFiles ;=====================================Problem Function Func _showSelected() Local $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True) Local $sSelect = _GUICtrlListView_GetItemText($sBlistView, $iSelect[1]) ; $sSelect = "C:\path to any text /file.txt" ; when testing this turn ^^^^ these 2 off _GUICtrlEdit_SetText($hEdit, FileRead($sSelect)) ConsoleWrite("$sSelect: " & $sSelect & @CR) ConsoleWrite("$hEdit: " & $hEdit & @CR) EndFunc ;==>_showSelected ;=====================================Problem Function Func _openSelected() $iSelect = _GUICtrlListView_GetSelectedIndices($sBlistView, True) $sSelect = _GUICtrlListView_GetItemText($sBlistView, $iSelect[1]) Run("cmd.exe /c " & """" & $sSelect & """",@ScriptDir,@SW_HIDE) EndFunc ;==>_openSelected My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted December 2, 2013 Moderators Solution Share Posted December 2, 2013 billo,I have seen this before - _GUICtrlListView_GetItemText has added an unseen extra character to the return so it is not recognised as a valid file. Just trim it and all works as you want: Local $sSelect = StringTrimRight(_GUICtrlListView_GetItemText($sBlistView, $iSelect[1]), 1)And if you are wondering how I found it the first time - I used StringLen. Finall, a freebie. I coded _RecFileListToArray to return a count in the [0] element - so why not use it? Global $FileList_A = _RecFileListToArray(@ScriptDir, "*", 1, 0, 0, 2) For $i = 1 To $FileList_A[0]M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
l3ill Posted December 2, 2013 Author Share Posted December 2, 2013 (edited) M23, Well first off thanks for ending my torment! And yes you are right I do wonder how you found that. (Insider Information?) I get the chr count issue but how do you know where the culprit was added? or is it just understood that it would be at the end? so why not use it? A rhetorical question I assume...? You Rock Melba! Thanks for your time! Now I can go find something else that I cant figure out Happy Holidays, Bill Edited December 2, 2013 by billo My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 2, 2013 Moderators Share Posted December 2, 2013 billo,As using ConsoleWrite to look at the path string compared to the literal string itself did not show any obvious errors, it was pretty clear that there had to be something at the end of the string. So I do not claim any supernatural powers - just common sense and understanding how to display strings as bytes. When you use StringToBinary you soon see that there is an 0x0A at the end of the string. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
l3ill Posted December 2, 2013 Author Share Posted December 2, 2013 ....much to learn. thanks again! My Contributions... SnippetBrowser NewSciTE PathFinder Text File Manipulation FTP Connection Tester / INI File - Read, Write, Save & Load Example Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now