LINE INPUT reads a line of text data from a file.
Syntax:LINE INPUT hFile AS HWND, Buffer AS STRING [, Limit AS INTEGER] Parameters:
|
👉 If the length of any line being read from the file is greater than the size, including any carriage return or new line indicators, of the receiving Buffer, default 2048 bytes, optionally specified in the Limit parameter, LINE INPUT will abort the application with a message identifying the line in the C translation at which the truncation was detected, as well as the truncated portion of the line of text that caused the error condition. The name of the file containing the too long line is also messaged, however, it is left up to the user to determine the exact location of the offending line in that file.
DIM FileName$ DIM z% FileName$ = "Test.txt" OPEN FileName$ FOR OUTPUT AS FP1 ? "Creating test file ..." FOR z% = 1 TO 10 FPRINT FP1, "This is not the end. THIS IS THE END "; STR$(z%) NEXT CLOSE FP1 DIM DynBuffer$ * 42 OPEN FileName$ FOR INPUT AS FP2 WHILE NOT EOF(FP2) LINE INPUT FP2, DynBuffer$ ? DynBuffer$ WEND CLOSE FP2 ? REDIM DynBuffer$ * 22 OPEN FileName$ FOR INPUT AS FP2 WHILE NOT EOF(FP2) LINE INPUT FP2, DynBuffer$, 22 ? DynBuffer$ WEND CLOSE FP2
Result:
Creating test file ... This is not the end. THIS IS THE END 1 This is not the end. THIS IS THE END 2 This is not the end. THIS IS THE END 3 This is not the end. THIS IS THE END 4 This is not the end. THIS IS THE END 5 This is not the end. THIS IS THE END 6 This is not the end. THIS IS THE END 7 This is not the end. THIS IS THE END 8 This is not the end. THIS IS THE END 9 This is not the end. THIS IS THE END 10 Error! - LINE INPUT truncation detected at PROGRAM line: 286 while reading file: D:\T\Test.txt The actual truncated line of text: This is not the end.
Reads a line of text data from the keyboard. Similar to the INPUT statement, LINE INPUT allows text including commas and quotation marks to be input from the keyboard. See also the INPUT statement.
Syntax 1:LINE INPUT Prompt AS STRING, Buffer AS STRING Parameters:
Syntax 2:LINE INPUT "", Buffer AS STRING Parameters: |
LINE INPUT allows you to collect characters typed on the keyboard, including commas, without the special need to use quotation marks. This is mostly compatible with PowerBasic and Qbasic except that, in BCX, when LINE INPUT is used to collect characters typed on the keyboard, the prompt is not optional.
👉 It is important to note that the receiving string variable must be a statically declared string variable. It cannot be a dynamically declared string because BCX's current translation emits the compile-time C operator "sizeof" which does not work for determining the number of bytes that a dynamically declared string can hold.
Simple string variables
DIM a$ LINE INPUT " Name? ", a$ PRINT a$
Name? Noobie Suzy Coder Noobie Suzy Coder
String Array variables
DIM b$[10,10] LINE INPUT " Name? ", b$[5,5] PRINT b$[5,5]
Name? Newby SiouxZe CodeR Newby SiouxZe CodeR