3

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

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33

4 Answers4

4

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.

BdR
  • 2,770
  • 2
  • 17
  • 36
1

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.

Alpha_Pi
  • 383
  • 2
  • 13
1

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
Zander Brown
  • 637
  • 8
  • 16
0

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

Sanuel
  • 1
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 16 '23 at 01:17