Using output of programs

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
zeynel1
Posts: 21
Joined: Sun 15 May 2022, 11:35

Using output of programs

Post by zeynel1 »

I just started to learn BBC BASIC. It's fun but how do I make data that I calculate usable? I mean, when I run my program a new window opens and the result is displayed. But the text there cannot be copied. So. how can I copy the results? Thanks

Do I need to write the results to a file? If so is this how it is done:

Code: Select all

      Drive$ = "c:"
      Path$  = "\test\"
      File$  = "try"
      Ext$   = ".ing"

      projekt$ = Drive$ + Path$ + File$ + Ext$

      print "Debug: ";projekt$

      A = openout projekt$

      print#A, stk_{(1,0)}
      close#A
From viewtopic.php?f=11&t=1117&p=3208&hilit=openout#p3208

(I'm on a Mac, the Manual seems to be for Windows)

Hated Moron
Posts: 97
Joined: Thu 07 Apr 2022, 10:10

Re: Using output of programs

Post by Hated Moron »

zeynel1 wrote:
Tue 17 May 2022, 22:18
I mean, when I run my program a new window opens and the result is displayed. But the text there cannot be copied. So, how can I copy the results?
There are several ways to save the results, here are a few:
  • You can copy the (textual) contents of the output window to the clipboard using the hotkey combination Ctrl+Tab. See Capturing the screen contents here.

  • You can spool the output to a file as well as to the screen:

    Code: Select all

          *spool output.txt
          PRINT "This is written to both the screen and a file"
          *spool
    
    (Use OSCLI if the destination path/file includes a variable)

  • You can redirect the output to a file instead of to the screen:

    Code: Select all

          file% = OPENOUT(file$)
          OSCLI "output " + STR$file%
          PRINT "This is written to a file but not to the screen"
          *output 0
          CLOSE #file%
    
  • You can explicitly write to a data file:

    Code: Select all

          file% = OPENOUT(file$)
          PRINT #file%, "This is written to a file"
          BPUT #file%, 10
          CLOSE #file%
    
  • You can create a textbox and write to that (the contents are initially selected and can be copied to the clipboard):

    Code: Select all

          INSTALL @lib$ + "dlglib"
          PROC_setdialogpalette
          dlg% = FN_newdialog("", 0, 0)
          text$ = "The quick brown fox jumps over the lazy dog"
          PROC_textbox(dlg%, text$, 101, 0, 0, 1000, 48, 0)
          dummy% = FN_showdialog(dlg%, 100, 800)
    
If you are unhappy with any aspect of this post, please report it to the forum administrator (click on the exclamation mark icon in the top-right corner) rather than complaining on the open forum or by private email.

zeynel1
Posts: 21
Joined: Sun 15 May 2022, 11:35

Re: Using output of programs

Post by zeynel1 »

Thanks for the detailed reply. That was very helpful.

zeynel1
Posts: 21
Joined: Sun 15 May 2022, 11:35

Re: Using output of programs

Post by zeynel1 »

(Use OSCLI if the destination path/file includes a variable)
I did not understand this. I read the OSCLI definition in the manual, how does it relate here? I put the output.txt here: ~/Library/Application Support/BBCBasic/, and it worked fine with *spool.

Hated Moron
Posts: 97
Joined: Thu 07 Apr 2022, 10:10

Re: Using output of programs

Post by Hated Moron »

zeynel1 wrote:
Wed 18 May 2022, 19:11
I read the OSCLI definition in the manual, how does it relate here?
'Star' commands are literal strings, they cannot include variables. Since it is bad practice to 'hard code' a file path into a program, this typically means that commands like *spool need to be issued using OSCLI so that they can contain variables:

Code: Select all

      OSCLI "spool """ + @usr$ + "temp.txt"""
This feature of BBC BASIC commonly confuses beginners, albeit that it has been like that from the very beginning, 40 years ago.
If you are unhappy with any aspect of this post, please report it to the forum administrator (click on the exclamation mark icon in the top-right corner) rather than complaining on the open forum or by private email.

zeynel1
Posts: 21
Joined: Sun 15 May 2022, 11:35

Re: Using output of programs

Post by zeynel1 »

Hated Moron wrote:
Wed 18 May 2022, 08:34

[*]You can spool the output to a file as well as to the screen:

Code: Select all

      *spool output.txt
      PRINT "This is written to both the screen and a file"
      *spool
I just noticed that I did not have the second *spool in my code but it still works. I only have *spoolon output.txt

What is the purpose of the second *spool?

Thanks

Hated Moron
Posts: 97
Joined: Thu 07 Apr 2022, 10:10

Re: Using output of programs

Post by Hated Moron »

zeynel1 wrote:
Wed 08 Jun 2022, 08:16
What is the purpose of the second *spool?
It closes the file, so it's quite important otherwise it will keep on spooling indefinitely. :o

The Help manual is your friend: all BBC BASIC statements, functions and commands are (or should be) documented there. This is what it says in the relevant section about *SPOOL:

"If the filename is omitted, any current spool file is closed and spooling is terminated."

If you do ever find something that you think should be in the Help manual but isn't, please let me know.
If you are unhappy with any aspect of this post, please report it to the forum administrator (click on the exclamation mark icon in the top-right corner) rather than complaining on the open forum or by private email.