Announcement

Collapse
No announcement yet.

Sequential files ..variable length

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sequential files ..variable length

    I want to write sequential files with non fixed lenth as :

    write #1 a(i)

    where i can vary from 1 to n
    Is it possible to write such a line , separated by "," ?

  • #2
    WRITE# in the help file looks promising.

    Advanced tip: see also the JOIN$ () function.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      join

      thanks , join$ is what i was looking for ! just to make it work with numeric values .

      Comment


      • #4
        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.

        Comment

        Working...
        X