zvd Posted January 19, 2007 Share 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) Link to comment Share on other sites More sharing options...
MHz Posted January 20, 2007 Share 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 Link to comment Share on other sites More sharing options...
Zedna Posted January 20, 2007 Share Posted January 20, 2007 MsgBox(0, "Test", FileRead("c:\temp\exclude.txt")) Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 20, 2007 Moderators Share 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. Link to comment Share on other sites More sharing options...
Paulie Posted January 20, 2007 Share 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... Link to comment Share on other sites More sharing options...
zvd Posted January 20, 2007 Author Share Posted January 20, 2007 Thanks! One thing - the number of lines in the text file may change.... Link to comment Share on other sites More sharing options...
Valuater Posted January 20, 2007 Share 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 Link to comment Share on other sites More sharing options...
zvd Posted January 20, 2007 Author Share 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). Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 20, 2007 Moderators Share 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. Link to comment Share on other sites More sharing options...
Helge Posted January 20, 2007 Share 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") Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted January 20, 2007 Moderators Share 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. 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