2

I'm trying to display a statement 1000 times in QBASIC (using for statement). I think the program works properly, but I cannot see the 1000 statements because I cannot scroll up and down in the output window of QBASIC. I can see only the last part of the 1000 statements.

FOR x = 1 TO 1000
    PRINT "maydie";
    PRINT
NEXT x
anonymous2
  • 219
  • 7
  • 21
MCB
  • 21
  • 1
  • Are you using actual QuickBASIC or are you using QB64 or some modern equivalent? If you are using the old 16 bit QuickBASIC made by Microsoft, you are not going to be able to "scroll" per se. What I would do is save the output to a text file and view the text file. – Robert Talada Apr 24 '19 at 13:08
  • Also, use colon (:) to denote multiple lines of code on one line, like this: FOR x = 1 TO 1000: PRINT "maydie"; PRINT :NEXT x – Robert Talada Apr 24 '19 at 13:16
  • @RobertTalada they simply forgot to format the code as code. Originally, those four commands were on separate lines. – anonymous2 Apr 24 '19 at 19:01
  • @RobertTalada I'm using QB64 – MCB Apr 27 '19 at 01:18
  • @CSTeacher Is there a reason why? QB64 is not something I would recommend for actual production business software. Your name is CS Teacher, are you a Computer Science teacher? Is this program for a demonstration to students? I feel like you should write this software in a language you have some familiarity with. The code I gave you works in Microsoft QuickBASIC. I don't know why it isn't working for you in QB64. Could be a bug or difference in behavior. For food ordering software, I recommend PHP/HTML/JS. If you give us a more clear idea of what you are trying to achieve, we can help. – Robert Talada Apr 30 '19 at 18:15
  • This is for my own professional development. Not a complicated food ordering system but a simple one only. Thank you so much for your help. :) – MCB May 01 '19 at 05:02

3 Answers3

0

That will be very hard. For QBasic you have to know how PRINT works. Than with look you could write an TSR program that does what you want in some other language. Alternative is store everything in array and create you own display routine with scrolling. But with 1000 lines will run into memory restrictions

Lee
  • 1,427
  • 9
  • 17
0

In short, unless you're using a modern take on QBasic, you can't.

What you can do is print the output to a text file:

OPEN "C:\somefile.txt" FOR OUTPUT AS #1
FOR x = 1 TO 1000 
  PRINT #1, "maydie":
  PRINT
NEXT x

This will write "maydie" to C:\somefile.txt 1000 times. Then use some text editor to view the output. You could even use a program to count the lines of text, something like OPEN "C:|somefile.txt" FOR INPUT AS #1: WHILE NOT EOF(1): INPUT #1, junk$: i = i + 1: WEND: PRINT "There were " + STR$(i) + " lines."

Robert Talada
  • 317
  • 1
  • 10
  • the codes you gave is effective but it can only print one print statement appropriately in the notepad.How to print multiple print statments? Actually I'm creating a simple food ordering system so that's why I'll be having a long output. – MCB Apr 27 '19 at 01:23
0

Though the other answerers are correct in saying that it is not inbuilt and hence not possible, I agree that this is very desirable! Consequently, I have time and time again devised scripts based on the following:

DIM text(1 to 1000) AS STRING
'Define text below: Here I've just defined it as every line being
'"maydie" with the value of the line number, but it could be whatever.

FOR i = 1 TO 1000
  text(i) = STR$(i) + "maydie"
NEXT i

CLS

position% = 0

FOR i = 1 to 25
  LOCATE i, 1: PRINT text(i); SPACE$(80 - LEN(text(i)));
NEXT i

DO
  x$=INKEY$
  IF x$ <> "" THEN
    SELECT CASE x$
      CASE CHR$(0) + CHR$(72) 'Up arrow
        position% = position% - 1
        IF position% < 0 THEN position% = 0
      CASE CHR$(0) + CHR$(80) 'Down arrow
        position% = position% + 1
        IF position% > 975 THEN position% = 975
      CASE CHR$(0) + "I" 'Page Up
        position% = position% - 24
        IF position% < 0 THEN position% = 0
      CASE CHR$(0) + "Q" 'Page Down
        position% = position% + 24
        IF position% > 975 THEN position% = 975
      CASE CHR$(27) 'ENDS the Program on ESC key.
        END
    END SELECT
    FOR i = 1 to 25
      LOCATE i, 1: PRINT text(i + position%); SPACE$(80 - LEN(text(i + position%)));
    NEXT i
  END IF
LOOP

Tested and works! If you want to use it multiple times in your program for multiple different text blocks, you can just turn it into a function and pass it the variables you want.

Robert Talada
  • 317
  • 1
  • 10
anonymous2
  • 219
  • 7
  • 21
  • Ooops, finally found a dosbox instance, and there's a bug... working on it. – anonymous2 Apr 24 '19 at 18:50
  • Ah, found it. Flipped the locate parameters like always. :) – anonymous2 Apr 24 '19 at 18:53
  • Actually I'm creating a simple food ordering system so that's why I'll be having a long output. I'm confused on how to incorporate the codes you gave on my food ordering system codes... – MCB Apr 27 '19 at 01:25
  • 1
    @CSTeacher Which part confuses you? The program enters into an infinite loop to display a portion of the resulting lines of text, and this code scrolls the text contained in the array based on arrow key input as is clearly commented. Ctrl+Break should exit the infinite loop. Press ESC to exit the program. CHR$(27) is ESC key. – Robert Talada Apr 30 '19 at 18:22