You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Sequential files have each line terminated with a $CRLF (or just $LF with Mac or Linux/Unix). The length of each line is not stored in the file, and is determined strickly by where the next $CRLF or $LF are found (or EOF if none are detected).
To write a single line, you can use a PRINT# statement. A $CRLF will be appended automatically when the items to be printed have been written to file. If you add a semi-colon at the end of the PRINT# statement, this will suppress the generation of the $CRLF. Thus, more than one PRINT# statement can put items on the same line in the file. If you use a comma (,) instead, you will insert a type of tab operator at that point. This could actually cause a tab to occur, or force a tab character (CHR$(9)) to appear at that point, or just insert a comma. Which occurs depends on the device being written to, and the implementation of that function in the language being used.
If you use this statement, PRINT#1, a b, and a is equal to 26, with b equal to 59, what will appear in your file will be this:
Code:
26 59
This would be exactly the same as PRINT#1,a;b. The semi-colon spacer can be left out, as it is optional.
If you instead use this statement PRINT#1 a,b then your file content will probably look like this:
Code:
26 59
If you want a comma to appear between the two, you could use this: PRINT#1, a "," b. Then you results would look like this:
Code:
26, 59
Numbers are printed with a leading sign character, which for positive numbers is normally a space (the alternative is to use the plus (+) sign). Some people use LTRIM$() or MID$(,2) to strip of the leading plus sign and save a bit of disk space. Negative numbers use the leading minus (-) sign, which is why LTRIM$() is often the better choice.
And the best way to ensure that you end up with a tab character separating a and b is to do it this way: PRINT#1, a $TAB b or PRINT#1, a CHR$(9) b
This is beneficial if you are writing CSV compatible sequential files.
If you want to write sequential files that are compatible with other OSes, you may need to do it this way: PRINT#1,a b $LF;
While it is possible to use the WRITE command instead of the PRINT command, I've never found it necessary to do so.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment