Announcement

Collapse
No announcement yet.

avoiding blank records in file ?

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

  • Paul G. Penn
    replied
    Why not use WRITE# instead of PRINT# ?

    If you're writing to an output file in the form:
    Code:
    INPUT "[S]creen, [D]isk, or [P]rinter"; OutDest$
     
    SELECT CASE OutDest$
       CASE "S"
           OutDestFile$ = "SCRN:"
       CASE "D"
           OutDestFile$ = "C:\TEMP\OUTDEST.TXT"
       CASE "P"
           OutDestFile$ = "LPT1:"
    END SELECT
     
    OPEN OutDestFile$ FOR OUTPUT AS #1, LEN=80
     
    PRINT #1, SomeData$
     
    CLOSE #1
    ...then PRINT# would work fine, as it sends the data line to the output destination as if it were the screen (values at every tab stop, tabs expanded to spaces, etc.) But if you wanted to send the data to the disk to be read back later by the INPUT# statement, why not use WRITE# instead, as it automatically inserts commas between data values and encloses strings in quotes, as in:

    Code:
     
    OPEN "C:\DATA1\CEMDATA.DAT" FOR OUTPUT AS #1
     
    WRITE #1, CemName$, CemLocation$, CemState$
     
    CLOSE #1
    This avoids the ending CR/LF at the end of each line and no blank line at the end of the file, what's written is written. The data line would look like this:

    Code:
     
    "Bunker Hill" , "Bethesda" , "Maryland"
    Using WRITE # instead of PRINT # would save a lot of needless processing to format the data line for the INPUT # statement to be able to read it.

    Leave a comment:


  • Mike Doty
    replied
    This demonstrates why not to remove last end of line marker.
    If the last line is blank means the program is writing a blank last line.

    'Output
    3
    1
    0
    Code:
     
    #COMPILE EXE
    #DIM ALL
    FUNCTION PBMAIN () AS LONG
     LOCAL h AS LONG
     h = FREEFILE
     OPEN "junk.txt" FOR OUTPUT AS #h
     PRINT #h,"1" 'last line
     ? "Bytes" + STR$(LOF(h))
     SEEK #h, LOF(h) -1
     SETEOF #h
     ? "Bytes" + STR$(LOF(h))
     CLOSE #h
     SLEEP 3000
     
     h = FREEFILE
     OPEN "junk" FOR INPUT AS #h
     ? "Bytes" + STR$(LOF(h))
     SLEEP 3000
    END FUNCTION

    Leave a comment:


  • Mike Doty
    replied
    To remove the last end of line marker $CRLF (why?)
    SEEK #h, LOF(h) -1
    SETEOF #h
    CLOSE #h

    Leave a comment:


  • Michael Mattias
    replied
    >Ok, at the bottom of each output file, there is a blank record. Can this be avoided?

    Um, sure. Don't execute the PRINT# statement if it would result in a blank line.

    Unless you mean you want to suppress the trailing CRLF inserted after the last line, in which case using the semicolon will work.

    Of course, you will now have to print the CRLF yourself where you want it...

    Code:
    IF ISFALSE "First output line"  THEN 
        PRINT #2 or #3, $CRLF; 
    END IF 
    IF Kount > 1000 then
         Print #2, Lastname$, Firstname$, Placeb$, Placed$;
    else
         Print #3, Lastname$, Firstname$,CemName$, State$;
    end if
    MCM

    Leave a comment:


  • Dave Stanton
    replied

    Print #3, Lastname$, Firstname$,CemName$, State$
    ;

    Leave a comment:


  • Robert E. Carneal
    started a topic avoiding blank records in file ?

    avoiding blank records in file ?

    Suppose I have something like:
    IF Kount > 1000 then
    Print #2, Lastname$, Firstname$, Placeb$, Placed$
    else
    Print #3, Lastname$, Firstname$,CemName$, State$
    end if


    Ok, at the bottom of each output file, there is a blank record. Can this be avoided? Just a few files (25 or so), I don't mind going in and taking out the blank line, but 100s of them it gets tedious. (I have 590 cemeteries I transcribed.)

    Is there a way to avoid the last record being blank?

    Yes, the variables contain data the last time they print to the file, as far as I can tell watching the debugger.

    Thanks.

    Robert
Working...
X