13.07.2015 Views

Turbo Basic

Turbo Basic

Turbo Basic

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

manual. Most of the ON something COSUB statements are related to event trapping.You need not specify to <strong>Turbo</strong> <strong>Basic</strong> that you want event-trapping code to begenerated. Event-trapping code is automatically generated whenever the compilerencounters any trappable instructions.An ExampleImagine an accounting program with dozens of menus to choose from and screensto fill out. As the author of this complex application, you want to include a helpscreen that provides basic infonnation about using it; for example, the keystrokesnecessary to edit data fields or to abort a menu selection. For the sake of simplicity,the help system we're about to describe isn't context-sensitive; that is, the sametext always appears without regard to where you are in the program when you'reasking for help.Let's make F' the help key. In other words, whenever F' is pressed, whateverthe context, help text will be put on the screen.The event-trapping capability of <strong>Turbo</strong> <strong>Basic</strong> allows you to code a "display helptext" feature in one place, and call it from allover the program with no furthereffort. Without event trapping, you'd have to check the status ofF' (with a COSUBto the help routine) every place in the program where a user might spend sometime.First, since this is a key you're trapping (not a joystick button or a light pen), youshould use the ON KEY(n) statement to define the subroutine to get control wheneverF' is pressed. n is an integer expression defining the key to be trapped; it sohappens that 1 is the name by which ON KEY knows function key 1.ON KEY(l) GOSUB DispHelpTextThis line says: When the key trap is turned on, check between every statementto see if F' has been pressed. If it has been pressed, call subroutine DispHelpText;if it hasn't, execute the next statement.Subroutine DispHelpText itself isn't much more than a series of PRINT statements.Since it doesn't want to disturb the part of the program that was interrupted,it saves the current cursor position before doing anything, and restores itafterward. It prints the help text on the bottom four lines of the screen, where byconvention no other part of the program writes.390 <strong>Turbo</strong> <strong>Basic</strong> Owner's Handbook

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

Saved successfully!

Ooh no, something went wrong!