Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print file to console one screen at a time

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Is there a simple way to print the contents of a file one screen at a time - like "|more" from a command line? I feel sure that this has an easy solution, but I haven't been able to find anything on it. I can change the console mode to more lines, but I'd rather have the print pause after each screen.

Thanks in advance!
 
I expect there are cleverer solutions, but because most QB screens seem to use 80 characters by 22 lines I usually count the number of lines I write to the screen then after 20 put

PRINT "Press any key to continue ..."
DO
LOOP UNTIL INKEY$ <> &quot;&quot;

then output another page of the file.

Incidentally, because some people's PIFs are different not everyone uses 80 x 22. Mine is more like 80 x 40, but if I use full screen mode the DOS window locks a lot.

Ray

 
Something I forgot, if you are opening a file for BINARY reading using GET then this works out to around 300 characters.

Ray
 
cls'detect screen metrics
Do
MAxX:=Pos(0)
print&quot;.&quot;;
Loop until Pos(0)=1'goto to next line after maximal position
Do
MaxY:=CsrLin'Rememeber previous vertical cursor position
print
Loop until MaxY=CsrLin'will not change at screen bottom
cls'Start output
'Print ...
if CsrLin=MaxY then
print &quot;-=[PRESS ANY KEY]=-&quot;;
Do Loop until inkey$<>&quot;&quot;
Do Loop until inkey$=&quot;&quot;
endif
 
Corrected listing:
CLS 'detect screen metrics
DO
MaxX = POS(0)
PRINT &quot;.&quot;;
LOOP UNTIL POS(0) = 1'goto to next line after maximal position
DO
MaxY = CSRLIN'Rememeber previous vertical cursor position
PRINT
LOOP UNTIL MaxY = CSRLIN'will not change at screen bottom
CLS 'Start output
'Print ...
IF CSRLIN = MaxY THEN
PRINT &quot;-=[PRESS ANY KEY]=-&quot;;
DO: LOOP UNTIL INKEY$ <> &quot;&quot;
DO: LOOP UNTIL INKEY$ = &quot;&quot;
END IF
 
One more:
PRINT operator must be added after line
LOOP UNTIL POS(0) = 1
if you want use listing &quot;AS IS&quot;
 
in short... Put this after your PRINT line:
l=l+1:if l>23 then print &quot;Press a key..&quot;;:l=0:a$=input$(1)

 
Q> Is there a simple way to print the contents of a file one screen at a time?

A> Yes. But, you'll have to write the code to read the file and print it to the screen. On top of that you'll have to provide variables for screen resolution and error checking to return the results.
--MiggyD

Never be afraid to try something new. Remember that amateurs built the Ark. Professionals built the Titanic.
 
To put it all together,
[tt]
LINE INPUT &quot;Enter filename: &quot;, filename$

ff% = FREEFILE
OPEN
filename$ FOR INPUT AS #ff%

'Detect screen size
DO
cols% = POS(0)
PRINT &quot; &quot;;
LOOP UNTIL POS(0) < cols%

PRINT
DO

rows% = CSRLIN
PRINT
LOOP UNTIL
rows% = CSRLIN

'Show the file
fileRow& = 0
thisLine$ = &quot;&quot;
showLine% = 0
DO WHILE NOT EOF(ff%)
screenRow% = 1

' The following handles lines wider than the screen that went past the end
' of the previous page. For the first new page containing a line, the
' previous part of the line is repeated. For subsequent pages, it is
' advanced just past the point that was visible on the previous page.

IF thisLine$ <> &quot;&quot; THEN
IF
(fileRow& AND 1) <> 0 THEN COLOR 15 ELSE COLOR 7
DO WHILE LEN(thisLine$) >= cols%
PRINT LEFT$(thisLine$, cols% - 1);
thisLine$ = MID$(thisLine$, cols%)
screenRow% = screenRow% + 1
IF screenRow% = rows% THEN
COLOR
7
PRINT &quot;--MORE--&quot;;
DO: key$ = INKEY$: LOOP WHILE key$ = &quot;&quot;
WHILE INKEY$ <> &quot;&quot;: WEND
EXIT DO
END IF
LOOP
IF LEN
(thisLine$) < cols% THEN
PRINT
thisLine$
screenRow% = screenRow% + 1
thisLine$ = &quot;&quot;
END IF
END IF

IF
screenRow% = rows% THEN
COLOR
7
PRINT &quot;--MORE--&quot;;
DO: key$ = INKEY$: LOOP WHILE key$ = &quot;&quot;
WHILE INKEY$ <> &quot;&quot;: WEND
ELSEIF
thisLine$ = &quot;&quot; THEN
DO WHILE NOT EOF
(ff%)
fileRow& = fileRow& + 1
IF (fileRow& AND 1) <> 0 THEN COLOR 15 ELSE COLOR 7

LINE INPUT #ff%, origLine$
thisLine$ = origLine$

IF LEN(thisLine$) >= cols% THEN
DO
PRINT LEFT$
(thisLine$, cols% - 1);
thisLine$ = MID$(thisLine$, cols%)
IF showLine% = 0 THEN
screenRow% = screenRow% + 1
IF screenRow% = rows% THEN
COLOR
7
PRINT &quot;--MORE--&quot;;
DO: key$ = INKEY$: LOOP WHILE key$ = &quot;&quot;
WHILE INKEY$ <> &quot;&quot;: WEND
EXIT DO
END IF
END IF
LOOP WHILE LEN
(thisLine$) >= cols%
IF LEN(thisLine$) OR (key$ = CHR$(27)) OR (LCASE$(key$) = &quot;q&quot;) THEN
thisLine$ = origLine$
EXIT DO
END IF
END IF

PRINT
thisLine$
thisLine$ = &quot;&quot;

IF showLine% = 0 THEN screenRow% = screenRow% + 1
showLine% = 0

IF screenRow% = rows% THEN
COLOR
7
PRINT &quot;--MORE--&quot;;
DO
DO
: key$ = INKEY$: LOOP WHILE key$ = &quot;&quot;
WHILE INKEY$ <> &quot;&quot;: WEND
'Allow enter or down-arrow to proceed just one line.
IF
(key$ = CHR$(13)) OR (key$ = CHR$(0) + &quot;P&quot;) THEN
showLine% = -1
LOCATE , 1 'Erase the --MORE-- prompt
PRINT &quot; &quot;;
LOCATE , 1
EXIT DO
ELSEIF
(key$ = CHR$(0) + &quot;H&quot;) THEN
BEEP 'Cannot scroll up with current design.
ELSE
EXIT DO
END IF
LOOP
IF
showLine% = 0 THEN EXIT DO
END IF
LOOP
END IF

'Remove the --MORE-- prompt.
LOCATE
, 1
PRINT &quot; &quot;;
LOCATE , 1

'Exit the loop if the user presses Q or escape.
IF (key$ = CHR$(27)) OR (LCASE$(key$) = &quot;q&quot;) THEN EXIT DO
LOOP
COLOR
7
IF EOF(ff%) THEN PRINT &quot;--EOF--&quot;

CLOSE #ff%

[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top