Groumphy 0 Posted June 4, 2005 Hello, I try to include a textual file of some lines in a control (Label). Unfortunately, each tests indicates an error to me. Here my method : 1 - To open the textual file 2 - To count the lines 3 - For each counted line, I read the lines in Array 4 - Concatenation of all Array in a variable 5 - Posting of the variable in control Isn't it easier to read a file by using IniRead ? Thank you for your councils... Groumphy ----------------------GroumphyMore information about me [Fr] Share this post Link to post Share on other sites
Jos 2,165 Posted June 4, 2005 Hello, I try to include a textual file of some lines in a control (Label).Unfortunately, each tests indicates an error to me.Here my method :1 - To open the textual file 2 - To count the lines 3 - For each counted line, I read the lines in Array4 - Concatenation of all Array in a variable 5 - Posting of the variable in controlIsn't it easier to read a file by using IniRead ? Thank you for your councils...Groumphy<{POST_SNAPBACK}>what about just reading the whole file into a variable and putting that into your Label ?Something like:$Filename="YourFileName" $FileText = FileRead($FIlename,FileGetSize($FileName)) $FileText = StringReplace($FileName,@CRLF,@LF) $ControlHandle = GUICtrlCreateLabel($filetext,10,10) ; - or - GUICtrlSetData($ControlHandle,$FileText) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Share this post Link to post Share on other sites
Groumphy 0 Posted June 4, 2005 Hello Jdeb,Thank you for your assistance.So easy ?!! Waw...Unfortunately that does not function. That registered (post) the name of the textual file and not the contents.I thought thereafter that it was initially necessary to open the textual file but the result is the same one.#include <GUIConstants.au3> GUICreate("My Gui", 200, 200, -1, -1) GUISetState(@SW_SHOW) $Filename= "test.txt" $FileText = FileRead(FileOpen($Filename, 0), FileGetSize($FileName)) $FileText = StringReplace($FileName, @CRLF, @LF) $ControlHandle = GUICtrlCreateLabel($FileText, 10, 10, 180, 180) ; - or - ; GUICtrlSetData($ControlHandle, $FileText) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WendHere the result :Not cool ----------------------GroumphyMore information about me [Fr] Share this post Link to post Share on other sites
MHz 80 Posted June 4, 2005 You need to store your FileOpen into a variable, so you can close it. Your StringReplace was trying to work the file, rather then the FileRead return. Try this: #include <GUIConstants.au3> GUICreate("My Gui", 200, 200, -1, -1) GUISetState(@SW_SHOW) $Filename= "test.txt" $handle = FileOpen($Filename, 0) $FileText = FileRead($handle, FileGetSize($Filename)) If @error = -1 Then Exit $FileText = StringReplace($FileText, @CRLF, @LF) $ControlHandle = GUICtrlCreateLabel($FileText, 10, 10, 180, 180) ; - or - ; GUICtrlSetData($ControlHandle, $FileText) FileClose($handle) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend Share this post Link to post Share on other sites
Groumphy 0 Posted June 4, 2005 Hello, Ok, it's now perfect !! Thanks... ----------------------GroumphyMore information about me [Fr] Share this post Link to post Share on other sites
Groumphy 0 Posted June 4, 2005 Why not this : Func _InsertTxtFileToLabel($iFilename, $iLeft, $iTop, $iHeight, $iWidth) $iHandle = FileOpen($iFilename, 0) $iFileText = FileRead($iHandle, FileGetSize($iFilename)) If @error = -1 Then Exit $iFileText = StringReplace($iFileText, @CRLF, @LF) $iVarCtrl = GUICtrlCreateLabel($iFileText, $iLeft, $iTop, $iHeight, $iWidth) ; - or - ; GUICtrlSetData($ControlHandle, $FileText) FileClose($iHandle) EndFunc #include <GUIConstants.au3> GUICreate("My Gui", 200, 200, -1, -1) GUISetState(@SW_SHOW) _InsertTxtFileToLabel("test.txt", "10", "10", "60", "60") _InsertTxtFileToLabel("test.txt", "10", "90", "180", "100") While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend Easylytoo Gniark ----------------------GroumphyMore information about me [Fr] Share this post Link to post Share on other sites
Groumphy 0 Posted September 5, 2006 Hello, In relation with this topics, I've a small problem. I make a small derivation of the previous script and in place of a GUICtrlCreateLabel, I use a GUICtrlCreateInput and the text is well include in the label but I've no scroll in the Input and the text of my textfile stay on one line... Where is my error ? Here is my code : #include <GUIConstants.au3> GUICreate("My Gui", 200, 200, -1, -1) GUISetState(@SW_SHOW) $Filename= "test.txt" $handle = FileOpen($Filename, 0) $FileText = FileRead($handle, FileGetSize($Filename)) If @error = -1 Then Exit $FileText = StringReplace($FileText, @CRLF, @LF) $ControlHandle = GUICtrlCreateInput($FileText, 10, 10, 180, 180, $ES_AUTOVSCROLL + $ES_READONLY) ; - or - ; GUICtrlSetData($ControlHandle, $FileText) FileClose($handle) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop Wend The problem come of then "Enter/Cariage". I've try to change the StringReplace @CRLF, @LF by @LF, @CRLF but it's the same. I've try too with : Chr(13), Chr(10). Is it possible to have an insertion of a textfile in an Input with a scroll ? Thanks for your help, G. ----------------------GroumphyMore information about me [Fr] Share this post Link to post Share on other sites
Groumphy 0 Posted September 5, 2006 Hello, I've found the problem. There was a bad formating of the textfile and I much use an Edit at place than an Input. Thanks for your help and sorry for the disturb. G. ----------------------GroumphyMore information about me [Fr] Share this post Link to post Share on other sites