Stoex Posted May 22, 2014 Share Posted May 22, 2014 expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=c:\users\steven\autoit trys\forms\axp.kxf $Form1_1 = GUICreate("Select Budget Reconciliation", 615, 440, 192, 124) GUISetFont(8, 800, 0, "MS Sans Serif") $ListView1 = GUICtrlCreateListView("", 24, 16, 313, 65) $OK = GUICtrlCreateButton("Select Folder", 352, 32, 105, 33) $Label1 = GUICtrlCreateLabel(" What file Do You Want To Open ?", 24, 88, 243, 17) $Button1 = GUICtrlCreateButton("List Load", 472, 32, 105, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### global $xx ;used in changing the text in the label global $lineComplete global $line While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK _OK() ;dialog box for selecting folder $label1 = GUICtrlSetData($Label1, $xx) ;used to change the text in the label ;- ;will not change again if multiple clicks - come back to it Case $Button1 ;load text to listbox _Myfile() $ListView1 = GUICtrlSetData($ListView1, $lineComplete) EndSwitch WEnd ;*below demos selecting file and folder - works Func _OK() ; Create a constant variable in Local scope of the message to display in FileSelectFolder. Local Const $sMessage = "Select a folder" ; Display an open dialog to select a file. Local $sFileSelectFolder = FileSelectFolder($sMessage, "") If @error Then ; Display the error message. MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.") Else ; Display the selected folder. MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder) $xx = $sFileSelectFolder EndIf EndFunc ;************************ ; code for file to populate list box Func _Myfile() $file = FileOpen("C:\Users\Stumpy\Documents\list.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $lineComplete = "" ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $lineComplete = $lineComplete & "|" & $line Wend EndFunc Here is my code (beginner at this). I'm just assembling GUI's and coding things to get the hang of it. Some of this works. I would like to stay on the path I started down and would like someone to take a look at it and comment on why the parts NOT working are NOT working. They are: Select Folder button works at bringing up the dialog box AND is suppose to also put the name of the folder chosen under the LISTVIEW Box (where it starts out asking a question). It works for the first click but nothing after that. I would think it should change anytime the button is clicked. The List Load button is my attempt to populate the List View Box from a txt file. I am using a function for that as well but nothing is happening. See Func _Myfile. So I need someone to look at the code and comment on "how its broken" for the two above issues. Some of the code is from the help files, some from the site both modified in the learning process. Thanks in advance. Link to comment Share on other sites More sharing options...
Geir1983 Posted May 23, 2014 Share Posted May 23, 2014 Function GUICtrlSetData is returning 0/1 if succcess. You then overwrite the handle to the $Label1 with this result. $label1 = GUICtrlSetData($Label1, $xx) ;Change this to: GUICtrlSetData($Label1, $xx) Link to comment Share on other sites More sharing options...
AndrewG Posted May 23, 2014 Share Posted May 23, 2014 1. It would be better to update the label at the end of the _OK() funtion instead of after the function call. See code below. 2. Not clear on what you wanted here; - Add listview items or add listview columns? I added listview items. See code below expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <MsgBoxConstants.au3> #Region ### START Koda GUI section ### Form=c:\users\steven\autoit trys\forms\axp.kxf $Form1_1 = GUICreate("Select Budget Reconciliation", 615, 440, 192, 124) GUISetFont(8, 800, 0, "MS Sans Serif") $ListView1 = GUICtrlCreateListView("Column 1", 24, 16, 313, 65) ;-----------------------Define column $OK = GUICtrlCreateButton("Select Folder", 352, 32, 105, 33) $Label1 = GUICtrlCreateLabel(" What file Do You Want To Open ?", 24, 88, 430, 17) $Button1 = GUICtrlCreateButton("List Load", 472, 32, 105, 33) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### global $xx ;used in changing the text in the label global $lineComplete global $line While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK _OK() ;dialog box for selecting folder ;~ Better to add the label update inside the _OK() function at then end . ;~ $label1 = GUICtrlSetData($Label1, $xx) ;used to change the text in the label ;- ;will not change again if multiple clicks - come back to it Case $Button1 ;load text to listbox _Myfile() $ListView1 = GUICtrlSetData($ListView1, $lineComplete) EndSwitch WEnd ;*below demos selecting file and folder - works Func _OK() ; Create a constant variable in Local scope of the message to display in FileSelectFolder. Local Const $sMessage = "Select a folder" ; Display an open dialog to select a file. Local $sFileSelectFolder = FileSelectFolder($sMessage, "") If @error Then ; Display the error message. MsgBox($MB_SYSTEMMODAL, "", "No folder was selected.") Else ; Display the selected folder. MsgBox($MB_SYSTEMMODAL, "", "You chose the following folder:" & @CRLF & $sFileSelectFolder) EndIf ;Added-----update label GUICtrlSetData($label1, $sFileSelectFolder) EndFunc ;************************ ; code for file to populate list box Func _Myfile() $file = FileOpen("C:\Users\Stumpy\Documents\list.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ;$lineComplete = "" ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop GUICtrlCreateListViewItem($line &"|", $ListView1) ;------------Create listview item, add lines from text file. ;$lineComplete = $lineComplete & "|" & $line Wend EndFunc Link to comment Share on other sites More sharing options...
Stoex Posted May 23, 2014 Author Share Posted May 23, 2014 AndrewG Thanks for reviewing this. I now see what you mean about the label update. Regarding the Myfile function - I had not seen the Ceate ListView Item, so that is new to me. So was my process using $lineComplete (see my code) just wrong or not thought out well? Any idea what was causing it to return nothing? Link to comment Share on other sites More sharing options...
Stoex Posted May 23, 2014 Author Share Posted May 23, 2014 Geir1983 Thanks for your comment on my update. Link to comment Share on other sites More sharing options...
AndrewG Posted May 23, 2014 Share Posted May 23, 2014 (edited) So was my process using $lineComplete (see my code) just wrong or not thought out well? Any idea what was causing it to return nothing? Using the GUICtrlCreateListView() function requires using the GUICtrlCreateListViewItem() to populate the Listview control. As far as "return nothing" I assume you mean the Listview control not showing text from your text file? The GUICtrlCreateListView() returns a zero if it fails to be created or a control id if successfully created. Which is just a number used to identify the control. The same applies to GUICtrlCreateListViewItem(). Carefully re-read in the help file about the GUICtrlCreateListView() function and you will see under the remarks heading to use GUICtrlCreateListViewItem(). To populate the control. Edited May 23, 2014 by AndrewG Link to comment Share on other sites More sharing options...
Stoex Posted May 23, 2014 Author Share Posted May 23, 2014 @AndrewG Went back and re-read it. Got it now. I was totally fixated on the GUICtrlSetData as the tool used to populated it. Makes a difference. Thanks again. 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