BBC BASIC for Windows
« color print »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:55pm



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 447 times)
Wendell
New Member
Image


member is offline

Avatar




PM


Posts: 28
xx color print
« Thread started on: Mar 16th, 2014, 01:09am »

Why does this program print the color twice
should print either red 0r green ?

REM HAVING COLOR PROBLEM
INPUT A$
IF A$="C" THEN (RED) ELSE (GREEN)
CLS
(RED)
COLOUR 1
PRINT TAB(16,29)A$
(GREEN)
COLOUR 2
PRINT TAB(16,29)A$
END
User IP Logged

Edja
Developer

member is offline

Avatar




PM


Posts: 60
xx Re: color print
« Reply #1 on: Mar 16th, 2014, 01:43am »

Quote:
Why does this program print the color twice
should print either red 0r green ?


When you input "C" you only see a green C on the screen because you first display a red C and immediately replace it with a green C

Change your second PRINT statement to
PRINT TAB(20,29)A$

and you'll see a red and a green C

Eddy
User IP Logged

Wendell
New Member
Image


member is offline

Avatar




PM


Posts: 28
xx Re: color print
« Reply #2 on: Mar 16th, 2014, 02:00am »

i am sorry not making myself clear. i only want red or green to print not both each time run prog. which ever is true. sorry i am a beginner. if "C" print it red . and that it
User IP Logged

Malvern
Guest
xx Re: color print
« Reply #3 on: Mar 16th, 2014, 03:08am »

Hi,
I think you imagine that it is going to jump to the labels. It doesn't but even if it did the program would complete the Green part last and show green. It might if you used some GOTO's but we don't really recommend that as you may have noticed.

You are making it more difficult than it really is. What changes the colour is the COLOUR statement so that is all that needs to be in the IF statement. Something like:

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

      END
 


I have my own colour problem: I can't tell if it prints red or green as I have a red-green colour deficiency! But it should work.


;)
« Last Edit: Mar 16th, 2014, 03:11am by Malvern » User IP Logged

Wendell
New Member
Image


member is offline

Avatar




PM


Posts: 28
xx Re: color print
« Reply #4 on: Mar 16th, 2014, 05:45am »

thank you i was making it harder than it was. but i am making progress. thank again
User IP Logged

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