| Merging COLOR, LOCATE and PRINTApril 6 2012 at 6:48 PM | AlGoreIthm (Login AlGoreIthm) | |
| In QBasic, both commands COLOR and LOCATE normally lead to a PRINT statement.
However, no structure in QBasic 'demands' the normal conclusion of using PRINT after either or both COLOR and LOCATE have been used.
This demonstrates how the 3 commands are meant to be used in conjunction.
The strings tx$ contain all the information needed to set the color, location and the message to be printed out - and then it's sent to sub-program DISPLAY which begins by chopping up tx$ into the necessary components and displaying the message with attributes.
By using a single datapack to carry all the information, the system only uses one disposable variable over and over again.
==============================================================================
DECLARE SUB DISPLAY (tx$)
SCREEN 12
tx$ = "140510Coordinates 5,10 in Yellow": DISPLAY tx$
tx$ = "111222Coordinates 12,22 in Light Blue": DISPLAY tx$
tx$ = "043306Coordinates 33,6 in Red": DISPLAY tx$
tx$ = "153821Coordinates 21,38 in White": DISPLAY tx$
tx$ = "025601Coordinates 56,1 in Green": DISPLAY tx$
END
SUB DISPLAY (tx$)
col% = VAL(LEFT$(tx$, 2))
x% = VAL(MID$(tx$, 3, 2))
y% = VAL(MID$(tx$, 5, 2))
t$ = RIGHT$(tx$, LEN(tx$) - 6)
COLOR col%
LOCATE y%, x%
PRINT t$;
END SUB |
| | Responses |
|
|