youtuber Posted May 1, 2021 Share Posted May 1, 2021 Is it possible to read line one by one after the loop? #include <Array.au3> #include <File.au3> $TxtFileHandle = @ScriptDir & "\TxtFile.txt" $ReadLines = "" Local $Var _FileReadToArray($TxtFileHandle, $Var) For $i = 1 to UBound($Var) -1 $ReadLines &= $Var[$i] & @CRLF Next MsgBox(0,"", $ReadLines) or #include <File.au3> $TxtFileHandle = @ScriptDir & "\TxtFile.txt" $OpenFileTxt = FileOpen($TxtFileHandle, 0) If $OpenFileTxt = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $ReadLines = "" For $i = 1 To _FileCountLines($TxtFileHandle) Step 1 $ReadLines &= FileReadLine($OpenFileTxt, $i) & @CRLF Next MsgBox(0, "", $ReadLines) FileClose($OpenFileTxt) Link to comment Share on other sites More sharing options...
Danp2 Posted May 1, 2021 Share Posted May 1, 2021 Sorry, but that's clear as mud. 🤔 You need to do a better job of describing what you are trying to accomplish. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
youtuber Posted May 1, 2021 Author Share Posted May 1, 2021 The $ReadLines variable does not fall into the Message box one by one after the for loop. She's reading lines collectively Link to comment Share on other sites More sharing options...
JockoDundee Posted May 1, 2021 Share Posted May 1, 2021 28 minutes ago, youtuber said: She's reading lines collectively You’re the one “collecting” them, with your &= $ReadLines &= FileReadLine($OpenFileTxt, $i) & @CRLF I think you owe “her” an apology Musashi 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
youtuber Posted May 1, 2021 Author Share Posted May 1, 2021 @JockoDundee If I don't add it will only read the last line! Link to comment Share on other sites More sharing options...
Danp2 Posted May 1, 2021 Share Posted May 1, 2021 Still clear as mud. Perhaps you want something like this? #include <Array.au3> #include <File.au3> $TxtFileHandle = @ScriptDir & "\TxtFile.txt" $ReadLines = "" Local $Var _FileReadToArray($TxtFileHandle, $Var) For $i = 1 to UBound($Var) -1 MsgBox(0,"", $Var[$i]) Next Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
youtuber Posted May 1, 2021 Author Share Posted May 1, 2021 (edited) MsgBox(0,"", $Var[$i]) Next I want the message box after the for loop Next MsgBox(0,"", $Var[$i]) Edited May 1, 2021 by youtuber Link to comment Share on other sites More sharing options...
Danp2 Posted May 1, 2021 Share Posted May 1, 2021 You aren't making any sense. You combine the individual lines into an single variable and then complain when the full variable is displayed in the MsgBox. Then I show you how to do it with a For loop, and you complain that you want the MsgBox to come after the Next. How do you expect to display the individual lines without using a MsgBox inside a For loop? Magic? 😒 Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
JockoDundee Posted May 1, 2021 Share Posted May 1, 2021 Let me take another tack: @youtuber, so you have this file, TxtFile.txt, right? 1) How many lines are in it? 2) How many times do you want msgbox to display by the time the program exits? 3) Give a example of a msgbox you EXPECT to receive when the program is working - USE REAL DATA, not variable names 4) If possible, post your TxtFile.txt If you do all these things, either you will figure it out then, or somebody will right after. Danp2 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
youtuber Posted May 1, 2021 Author Share Posted May 1, 2021 TxtFile.txt its content Line1 Line2 Line3 Line4 ... Danp2 1 Link to comment Share on other sites More sharing options...
Trong Posted May 1, 2021 Share Posted May 1, 2021 Everybody and me don't understand what you want to achieve. Below is the code I use when working with lines and large files. Global $iFileIN = @ScriptFullPath Global $sNewFileContent, $sFileContent, $sLine, $Read_Line = 0, $iLineCount = 0 While 1 $Read_Line = $Read_Line + 1 $sLine = FileReadLine($iFileIN, $Read_Line) If @error <> 0 Then ExitLoop $iLineCount += 1 $sFileContent &= $sLine & @CRLF $sNewFileContent &= _Work_On_This_Line($sLine, $iLineCount) & @CRLF WEnd MsgBox(0,'xXx',$sNewFileContent) Func _Work_On_This_Line($iLine, $iLineCount) ; Do somethink here ConsoleWrite('-LINE ' & $iLineCount & ': ' & $iLine & @CRLF) Return $iLine EndFunc ;==>_Work_On_This_Line Regards, Link to comment Share on other sites More sharing options...
JockoDundee Posted May 1, 2021 Share Posted May 1, 2021 (edited) Please tell me you’re a troll... Line1 Line2 Line3 Line4 Edited May 1, 2021 by JockoDundee PnD 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Nine Posted May 1, 2021 Share Posted May 1, 2021 Instead of beating a MsgBox, use a Gui ListBox that you can fill during the loop, and lines will show all along the way. youtuber 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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