Hardware Reference
In-Depth Information
don't need a full Windows environment for your application these compilers
can make a useful starting point.
Developing Microsoft
BASIC for DOS
programs
Since it is relatively easy to write and enter Microsoft BASIC for DOS programs,
it is unfortunately all too easy to develop bad habits. Furthermore, the end
result produced by an unstructured program (i.e. 'quick and dirty code') can
sometimes be indistinguishable from that produced by a program which is highly
structured. The difference only becomes important when the time comes for
extending, modifying, or maintaining the program. With structured code this is
a relatively simple matter. An unstructured program, on the other hand, may be
a tangled nest of haphazard code and a major modification to the program may
well result in the need for a complete rewrite. This can hardly be described as
efficient!
There are a number of techniques that can be used to assist in the production
of efficient structured code. First and foremost, it is vitally important to get into
the habit of being consistent in the layout of your programs and in the names
used for variables. Failure to do this will make it extremely difficult to port
sections of code from one program to another. This is a highly desirable feature
which will save many hours of work. An efficient procedure for, say, accepting
keyboard input and verifying that it is numeric, truncating it to integer, and
confirming that it is within a given range, can be useful in a huge variety of
control applications. There is absolutely no reason why an efficient code module
that performs such a function should not be included in every program that you
write. Once written, you will never do it again!
Variable types
Wherever possible, integer numeric variables should be used in order to min-
imize storage space and increase processing speed. Floating point variables,
which have considerable processing and storage overhead, should be avoided.
Integer variables are normally recognized by a trailing %. Thus t represents a
floating point numeric variable while t% represents an integer numeric variable
and t$ represents a string variable.
Integer variables require 2 bytes for storage and values can be whole numbers
(i.e. no decimal points) ranging from 32 768 to + 32 767. Microsoft BASIC
for DOS also supports long integers (in which each occupy 4 bytes of storage),
and both single- and double-precision floating point numbers (see Table 6.1).
String variables comprise a sequence of characters (letters, numbers, and
punctuation). Microsoft BASIC for DOS supports both fixed and variable length
strings (the length of the former type must be declared). In either case, the
maximum length permitted is 32 767 characters.
Variable names
In order to aid readability, it has become fashionable to use relatively long names
for variables. Happily, where a BASIC program will eventually be compiled, the
overhead associated with long variable names applies only to the source files. It
is thus permissible to use more meaningful variable names in such applications.
Whether or not one is using a compiled BASIC, it is essential to maintain
Search WWH ::




Custom Search