how to know the last printed text in QBasic

281 views Asked by At

I want to know that how to get the last printed text in QBasic. Like if the program prints several lines, then how to get the last line printed.

Like this-

Print "aaaaaaa"
Print "bbbbbbb"

Then the program will get the last printed line i.e. bbbbbbb

4

There are 4 answers

0
BdR On BEST ANSWER

Something like this maybe?

str$ = "aaaaaaa"
PRINT str$
str$ = "bbbbbbb"
PRINT str$
PRINT "last printed line:"; str$

Alternatively, as explained here, you can retrieve characters from screen memory by using PEEK at segment &HB800 , so something like this

DEF SEG = &HB800
mychar = PEEK(1) 'etc

You'd have to keep track of on which line was last printed to know where exactly you need to PEEK, so that will probably get very complicated very quickly...

For that reason I recommend you to rethink what it is exactly that you are trying to accomplish here because "screen scraping" like this is usually just a bad idea.

1
Sanuel On

Mamponteng

Write the last two characters of mamponteng in qbasic Write the first three what is the length of the word above write the following letters of the word above using a qbasic function(ponte) write the word in both upper and lower

0
Alpha_Pi On

Given that last printed string did not end with semicolon, this code should do the trick:

 FOR char.num = 1 TO 80
 last.line$ = last.line$ + chr$(SCREEN(CSRLIN - 1, char.num))
 NEXT char.num
 PRINT "Content of last line printed to is:"; last.line$

Explanation: CSRLIN returns the current line of the cursor. SCREEN(y, x) returns the ascii-code of the character at y, x position (line, row) on the screen. Each time a string not ending with semicolon is printed to the screen, it is printed on the current line (y position) of the cursor, which is then incremented by one.

0
Zander Brown On

I realise this question already has an accepted answer but I have my own solution where instead of trying to work out what PRINT last PRINTed you instead use you own PRINT SUB in this example MYPRINT. While its not perfect and it only takes strings (hence STR$(123) and uses SHARED variables which are not necessarily advisable it is nicer than poking in the memory.

DECLARE SUB MYPRINT (text$)
DIM SHARED lastprint$

MYPRINT ("Hello, World!")
MYPRINT (STR$(123))
MYPRINT ("Hi Again")
MYPRINT (lastprint$)

SUB MYPRINT (text$)
        PRINT (text$)
        lastprint$ = text$
END SUB

The output:

Hello, World!
 123
Hi Again
Hi Again