zvd 0 Posted January 19, 2007 Hello, in the following example, exclude.txt has 5 lines of text. The message box pops up 5 times to display each line of text. How can I make just one message box pop up with all 5 lines of text on one line? Thanks| $file = FileOpen("c:\temp\exclude.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop MsgBox(0, "Test", $line) WEnd FileClose($file) Share this post Link to post Share on other sites
MHz 80 Posted January 20, 2007 (edited) Just store each line into a variable Global $total $file = FileOpen("c:\temp\exclude.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $total = $total & @CRLF & $line WEnd FileClose($file) MsgBox(0, "Test", $total) Edit: Code mistake fixed. Edited January 20, 2007 by MHz Share this post Link to post Share on other sites
Zedna 276 Posted January 20, 2007 MsgBox(0, "Test", FileRead("c:\temp\exclude.txt")) Resources UDF ResourcesEx UDF AutoIt Forum Search Share this post Link to post Share on other sites
SmOke_N 210 Posted January 20, 2007 You're example would only ever read the first line anyway. You never increase $line. $sString = StringReplace(StringStripCR(FileRead("c:\temp\exclude.txt")), @LF, ' ') MsgBox(64, 'Info', $sString)The Carriage Returns/Line Feeds are replaced by spaces. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Share this post Link to post Share on other sites
Paulie 26 Posted January 20, 2007 $file = FileOpen("c:\temp\exclude.txt", 0) Global $Line[6] If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $Message = "" For $i = 1 to 5 $line[$i] = FileReadLine($file,$i) $Message= $Message&$Line[$i]&@CRLF Next If @error = -1 Then ExitLoop MsgBox(0, "Test", $message) WEnd FileClose($file) Yeah, I was beat... Share this post Link to post Share on other sites
zvd 0 Posted January 20, 2007 Thanks! One thing - the number of lines in the text file may change.... Share this post Link to post Share on other sites
Valuater 129 Posted January 20, 2007 (edited) i use file read to array from help #include <file.au3> Dim $aRecords If Not _FileReadToArray("error.log",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 to $aRecords[0] Msgbox(0,'Record:' & $x, $aRecords[$x]) Next[/color] 8) Edited January 20, 2007 by Valuater Share this post Link to post Share on other sites
zvd 0 Posted January 20, 2007 Yes, I tried working with that but had the same problem - trying to get just one message box with all the text on just one line (no CRLF's). Share this post Link to post Share on other sites
SmOke_N 210 Posted January 20, 2007 Yes, I tried working with that but had the same problem - trying to get just one message box with all the text on just one line (no CRLF's).I gave you the answer then.http://www.autoitscript.com/forum/index.ph...st&p=296180 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Share this post Link to post Share on other sites
Helge 3 Posted January 20, 2007 You're example would only ever read the first line anyway. You never increase $line.Not true. If he hadn't used FileOpen but given FileReadLine the filename instead, it's true however. When FileReadLine is given a handle it loops through the file, line by line. $sFile = FileOpenDialog("", "", "Text (*.*)") If @error Then Exit $hFile = FileOpen($sFile, 0) If @error Then Exit While 1 $sLine = FileReadLine($hFile) If @error Then ExitLoop MsgBox(64, "", StringLeft($sLine, 40) & "...") WEnd MsgBox(64, "", "Finished") Share this post Link to post Share on other sites
SmOke_N 210 Posted January 20, 2007 (edited) Not true. If he hadn't used FileOpen but given FileReadLine the filename instead, it's true however. When FileReadLine is given a handle it loops through the file, line by line. $sFile = FileOpenDialog("", "", "Text (*.*)") If @error Then Exit $hFile = FileOpen($sFile, 0) If @error Then Exit While 1 $sLine = FileReadLine($hFile) If @error Then ExitLoop MsgBox(64, "", StringLeft($sLine, 40) & "...") WEnd MsgBox(64, "", "Finished")I can honestly say, I didn't... I didn't even know that ... thanks. Edited January 20, 2007 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Share this post Link to post Share on other sites