07.05.2015 Views

Download - True BASIC

Download - True BASIC

Download - True BASIC

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Libraries and Modules<br />

107<br />

SELECT CASE how$<br />

CASE “L”<br />

INPUT PROMPT how$: angle<br />

CALL Left(angle)<br />

CASE “R”<br />

INPUT PROMPT how$: angle<br />

CALL Right(angle)<br />

CASE “F”<br />

INPUT PROMPT how$: distance<br />

CALL Forward(distance)<br />

CASE “B”<br />

INPUT PROMPT how$: distance<br />

CALL Back(distance)<br />

CASE “C”<br />

CALL ClearScreen<br />

CASE “S”<br />

STOP<br />

CASE ELSE<br />

END SELECT<br />

END IF<br />

LOOP<br />

END<br />

Sharing Channel Numbers<br />

Channel numbers may be shared and passed as parameters, but they cannot be public. Because channel numbers<br />

may be shared, modules are often used to isolate the interface to files, logical windows, or a printer. You will find<br />

much more information on channel numbers and their use in Chapter 12 “Files for Data Input and Output.”<br />

The following example uses logical windows to illustrate shared channels. Logical windows are described in Chapter<br />

13 “Graphics.” Briefly, however, you need to know that <strong>True</strong> <strong>BASIC</strong> defines the default logical window with coordinates<br />

0 to 1 from left to right and 0 to 1 from bottom to top. Thus, the lower left corner of the default window is 0, 0 and<br />

the upper right is 1, 1. You can define smaller logical windows within a physical window by specifying the left, right,<br />

bottom, and top coordinate limits in an OPEN statement, as in the following module. The WINDOW statement tells<br />

<strong>True</strong> <strong>BASIC</strong> where to send subsequent output (see Chapter 13 “Graphics”).<br />

MODULE Timer<br />

SHARE start, #1, #2<br />

OPEN #1: SCREEN 0, .8, 0, 1<br />

OPEN #2: SCREEN .85, 1, 0, 1<br />

LET start = Time<br />

CALL Clock<br />

SUB Clock<br />

LET t = Time<br />

WINDOW #2<br />

CLEAR<br />

PRINT Round(t - start, 1)<br />

WINDOW #1<br />

END SUB<br />

! Starting time, 2 windows<br />

! Working window<br />

! Time window<br />

! Use built-in function<br />

! Print to time window<br />

! Switch back to working window<br />

END MODULE<br />

In this example, <strong>True</strong> <strong>BASIC</strong> would open the logical windows and print the initial time in window #2 as part of<br />

module initialization before it executes the main program. Output from the main program will be printed in window<br />

#1. The main program can update the running time whenever it wishes with the statement:<br />

CALL Clock

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!