Cool Line Input feature - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: Chatting and Socializing (https://staging.qb64phoenix.com/forumdisplay.php?fid=11) +--- Forum: General Discussion (https://staging.qb64phoenix.com/forumdisplay.php?fid=2) +--- Thread: Cool Line Input feature (/showthread.php?tid=883) |
Cool Line Input feature - bert22306 - 09-13-2022 Well, okay, this might also be one of those situations where I'm the only guy who didn't get the memo. If we create a text file with multiple lines, each line ending with a <return>, and we use Line Input to read each line as one long string, the Line Input command only reads the top line in the file. Okay, I thought, I can deal with that. I can always copy-paste the other lines to the top, to input each line. No need! All you have to do is go back to that Line Input statement, and it will automatically read the next line down, in the text file. How cool is that? Code: (Select All) Dim Shared a$ I add one line at the bottom of the text file, which says "stop," to end the process. For this demo program, the subroutine only prints the line input from the text file. RE: Cool Line Input feature - Pete - 09-13-2022 Unless I misunderstood the post, QBasic / QB64 has always acted in this manner. I'll have a talk with our mail room, memo division. Basically, LINE INPUT inputs the line up to the carriage return and since we are working with a sequential file here, that index place is maintained in memory; therefore, the next line input statements turns out the next line of text up to the next carriage return. Now if you ever use binary, you have two choices. You can use LINE INPUT in QB64 only (not QBasic) with open for binary. It's faster, and works the same as a sequential read, but you can use it with get to input the entire text file at once. Of course then, you have to parse it if you want to read it line by line. I use the latter method in my WP routines. Pete RE: Cool Line Input feature - JRace - 09-13-2022 Yeah, Line Input reads one line each time you use it, into one string variable that you specify. To read more lines, you need to use a loop or multiple Line Inputs. The underlying file I/O handler keeps track of where you left off after the last read. Code: (Select All) Print "Input allows us to read multiple comma-separated numeric values...." |