Help with"invalid channel at line..." error - newbie question

Discussions related to database technologies, file handling, directories and storage
Richard Russell
Posts: 272
Joined: Tue 18 Jun 2024, 09:32

Re: Help with"invalid channel at line..." error - newbie question

Post by Richard Russell »

JMR wrote: Wed 12 Mar 2025, 09:51 I've now replaced what I'd had with the following:

Code: Select all

PRINT#outfile%,STR$(nc),STR$(nh),STR$(no),STR$(nn)
BPUT#outfile%,LF
The problem with that code is that only the last number STR$(nn) is receiving the LF terminator, the others aren't.

When you PRINT the numbers to the screen you are separating them by spaces, but when you are writing them to the file you are separating them by carriage returns.

If you want the file to contain the same as was written to the screen, then separate the numbers with spaces in both cases:

Code: Select all

      PRINT nc;"  ";nh;"  ";no;"  ";nn  : REM Output to screen
      PRINT#outfile%, STR$(nc)+"  "+STR$(nh)+"  "+STR$(no)+"  "+STR$(nn) : REM Output to file
      BPUT#outfile%,LF
All I require is to write all results that appear on the screen, to a text file ...it can't be that difficult.
It isn't. To output to a file what is sent to the screen simply use *SPOOL (it outputs to both the screen and the file):

Code: Select all

      OSCLI "SPOOL " + CHONRESULTS$
      PRINT nc;"  ";nh;"  ";no;"  ";nn
      *SPOOL
Alternatively use *OUTPUT to redirect the output to the file (that way it won't appear on the screen at all):

Code: Select all

      outfile% = OPENOUT(CHONRESULTS$)
      OSCLI "OUTPUT " + STR$outfile%
      PRINT nc;"  ";nh;"  ";no;"  ";nn
      *OUTPUT
      CLOSE #outfile%