BBC BASIC for Windows
« color print »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 11:48pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: color print  (Read 449 times)
Malvern
Guest
xx Re: color print
« Reply #5 on: Mar 16th, 2014, 4:14pm »

Before we leave this I think we need to show how what you were trying to write could be written.
Labels are used as places to jump to but are not the best way of controlling the program flow. Procedures are much better. At the end of a procedure the program returns to the next statement after the calling statement. It is a return ticket in other words: out, do the work and then return back to the next statement.

Your initial program could have been written like this:
Code:
 
     INPUT A$
      CLS
      IF A$="C" THEN PROCred ELSE PROCgreen

      END

      DEF PROCred
      COLOUR 1
      PRINT TAB(16,29)A$
      ENDPROC

      DEF PROCgreen
      COLOUR 2
      PRINT TAB(16,29)A$
      ENDPROC
 


And you would want to write it in this way if you wanted to do more things rather than just print.

Before going too much further I would suggest that you take a look at the Tutor that is linked to the BB4W Help menu.
It may seem like going back to school but it is very good and will help you progress faster than by trial and error. By all means write little programs to test your understanding. Better still is to find a programming buddy. I expect there are people here that would offer to help. We all had to learn and tend to forget how difficult it was to begin with.



« Last Edit: Mar 16th, 2014, 4:21pm by Malvern » User IP Logged

rtr
Guest
xx Re: color print
« Reply #6 on: Mar 16th, 2014, 4:50pm »

on Mar 16th, 2014, 4:14pm, Malvern wrote:
Your initial program could have been written like this:

Indeed it could, but it's a style that has its origins in the original BBC Microcomputer BASIC which, critically, had no multi-line IF...ELSE...ENDIF statement. This meant that the only way to avoid GOTOs was to put the conditional clauses in PROCedures, as you illustrate.

With the availability of a multi-line IF...ENDIF (in ARM BASIC and BB4W) I would consider this preferable:

Code:
      INPUT A$
      CLS
      IF A$="C" THEN
        COLOUR 1
        PRINT TAB(16,29)A$
      ELSE
        COLOUR 2
        PRINT TAB(16,29)A$
      ENDIF 

As a general rule I would move code into a PROC only if it is called from multiple places, or if it's sufficiently lengthy that including it 'inline' within an IF...ENDIF statement causes the structure to be unclear (for example if you can't seen the entire conditional clause on one screen), or if it uses LOCAL variables.

Richard.
« Last Edit: Mar 16th, 2014, 5:03pm by rtr » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls