<<

QuickBASIC (version 4.5): a user- friendly computer programming tool

J. CASE

Among those with pretensions to computer literacy, as supplied with IBM and IBM-compatible computers, the BASIC progtamming language is commonly spoken are interpreters of the BASIC language. They are easy of with contempt. However appropriate that may seem to learn and use but will inevitably lead the amateur to someone with the intelligence and perseverance to programmer into bad habits that may prove difficult become proficient in Pascal, it overlooks the purpose to break. Early did not always improve the for which BASIC was written in the first place. The situation. They merely converted programs that had acronym stands for Beginners’ All-purpose Symbolic been written and tested using the interpreter. Modern Instruction Code. For beginners, its easy-to-learn syntax BASIC compilers, however, offer a complete program- makes BASIC an ideal choice for those wanting to jump ming environment, making the interpreted form of the right in and write functional with little or no language virtually redundant. Among those currently prior preparation. It’s a pity that the same simplicity available, ’s QuickBASIC Version 4.5 may be of use leads to the creation of inelegant code and so considered one of the worlds best bargains in computer readily engenders bad programming habits. software. At any rate, it has qualities that justly entitle With languages like and Pascal, all variables have BASIC to the same respect that is so commonly paid to he declared before being applied. A considerable to the more posh computer languages. It is easy to learn, amount of preparatorytime must be spent in designing yet has capabilities hitherto found only in Pascal and the program before it can be written and tested. BASIC, the like. It allows for structured programming and is on the other hand, has an almost limitless capacity to no more complicated to work with than some of the tolerate last-minute changes. Fresh lines of code can simplest of word processors. be created as necessity dictates, and, by being numbered appropriately, can be executed in almost any order The versus Interpreter flow of the program can be directed to the new code Before going on to consider the many virtues of at will with a simple GOTO statement-or, perhaps a QuickBASIC, it may be helpful to review briefly the little more forgivably, by using GOSUB and RETURN. essential differences between an interpreted and a com- The same simplicity of use is one of the main disad- piled version of a computer program. vantages of BASIC. Unplanned changes lead to the An interpreter translates each statement of code into generation of “spaghetti code,” winding its way intri- machine language as it goes along. Providing the syntax cately from one part of the program to another and and grammar are correct, the statement is then executed coiling back on itself in infinite complexity. Therein by the computer and the interpreter proceeds to the lies the fundamental distinction between structured and next one. If an error is encountered, the program stops unstructured progamming. Therein, too, is the difference and an error message is displayed. When a statement between code that is interpretable when the need arises occurs more than once in a program, the interpreter to change it and code that defies unraveling, even by approaches it afresh each time, laboriously translating the misguided soul responsible for its creation. it again. Consequently, the execution of a home-made All the bad things people say about BASIC are largely BASIC program can seem painfully slow by comparison true enough as they apply to the interpreted form of with professionally written software, whether of com- the language that is usually supplied with a computer’s mercial origin or otherwise. Naturally, the program is . To be fair, all the good things they incapable of running on its own. The BASIC interpreter say are true, too, for that matter. BASICA and GWBASIC, must be loaded first, since it has to be present to con-

VOLUME 5, NUMBER 1, 1989 15 J. CASE

vert the code into instructions the computer can Subsequent Developments understand. The introduction of Version 2 of QuickSASIC in 1986 A compiler, by contrast, translates all statements of brought several significant practical improvements. The code into the necessary machine language in advance, provision of a full-screen editor enabled a QuickBASIC converting them into a stand-alone program that can program to be wholly written within the environment he executed directly from the DOS command line. The of the compiler. Moreover, the ability to dispense with gain in convenience and speed is impressive. It is not line numbers brought true structured programming in unusual for a compiled BASIC program to run 30 or BASIC within easy reach. At the same time, this was 40 times faster than did the original code under the not imposed as an inescapable condition, as it is in interpreter. Pascal. There were other significant improvements, as The first BASIC compiler for the IBM PC retailed at there were, again, with Version 3 and, more recently, a price around $600. That was too high a figure to with Versions 4.0 and 4.5. No doubt the future will deserve serious consideration by an amateur pro- see further improvements that would be hard to imagine grammer From that viewpoint, Version 1 of QuickBASIC at this point. In the meantime, QuickBASIC 4.5 is just came as a Godsend when it was introduced at a list about everything the amateur programmer could wish price under $100 in 1985. At that point, however, it for. did little to improve the structure of a BASIC program. It was still necessary to use the interpreter to write and Using QuickBASIC, Version 4.5 test the code for errors before going on to compile it. All that is needed to create a new program is to load The procedure was cumbersome and inconvenient. For the compiler by typing “QB” at the DOS prompt, then one thing, the BASIC interpreter saves its files to disk select the “New program” option from the “File” menu, in a “tokenized” form that the compiler is incapable and start typing. Naturally, it is assumed that the user of reading. It was necessary to remember to use the is familiar with interpretative BASIC and thus already switch that causes the file to be written in ASCII format. knows the syntax and functions of the language. If not, After that, it was necessary to exit the interpreter, then however, Version 4.5 possesses a useful feature not invoke the compiler to convert the BASIC source code present in Version 4.0. This is the ability to bring up into an OBJect file. Finally, the OBJect file had to be context-sensitive help on the screen. Pressing Function LlNKed with another utility to create the stand-alone Key 1 while the cursor is on a BASIC statement brings EXEcutable program that was the original objective. up a display that explains the use of that statement in All this could be extremely tedious, to say the least, complete and helpful detail. This remarkable enhance- especially as the compiler commonly reported errors ment makes the manual redundant (although one can not previously suspected. A few programming practices still be purchased at extra cost). tolerated by the interpreterwere disallowed by the com- In writing a program, errors of syntax are recognized piler; hence, it was frequently necessary to reload the as they are entered, thanks to the ‘Smart editor” feature interpreter to amend and retest the source code In saving of the compiler. This can be very useful as an aid in the corrected program each time, it was again essential writing error-free code, but it is also irritating at times. to remember the compiler’s aversion to the tokenized Mercifully, it can be turned off, if desired. Several format used as the default by the interpreter. And, after significantly enhanced functions have been incorporated. each revision, it a necessary to return from the inter- For one thing, IF. . .THEN. . .ELSE constructions are preter to the DOS command line, then load the compiler easier to use, as they are no longer confined to one line, again for further action. and a DO. ..UNTIL loop has also been made available More recent updates of the compiler embodied signifi- to supplement the more limited capabilities of FOR. . . cant improvements. Version 4.5, still at a list price of TO and WHILE. . .WEND. The lack of line numbers under $100 (and available for as little as $65 from a does not preclude the use of GOTO or GOSUB and wide selection of discount software retailers), is as dif- RETURN, either. They are to be avoided ifpossible, but ferent from Version 1 as chalk is from cheese. It is also it is sometimes useful to be able to divert the flow of as little deserving of the criticism heaped on BASIC by the program at will. If necessary, an alphabetic or the programming snobs as even the most respectable alphanumeric label can be assigned to facilitate reaching of computer languages, whatever that is considered to be. the appropriate line(s) of code. This can be made descrip-

16 IMMUNOHEMATOLOGY QuickBASIC program (version 4.5)

tive of the purpose served by those lines of code. For saved. If an additional existing module is to be included instance, a subroutine to read a diskfile can be labeled in a program alreadyloaded, the “Merge” option from ReadFile: and invoked by placing the command GOSUB the “Edit” menu enables it to be incorporated. ReadFile in the body of the program. Better still, a A program can be compiled to memory and run as separate subprogram named ReadFile can be created often as necessary during its development. Finally, when and can simply be called from the main program when the writer is satisfied with its performance, it can be necessary. Descriptive variables can also be used without converted to an EXEcutable file by choosing “Make EXE overtaxing the memory available for the program. The file” from the “Run” menu. At this point, the compiler use of suchvariable names as CustomerName$ and Item- will handle the entire operation without any further Cost! will make it easier to follow and understand the intervention (assuming, of course, that it finds no errors). code later than the more cryptic CN$ and IC! yet will It creates and saves an OBJect file for each module, then not add one extra byte to the size of the final compiled automatically invokes the LINKer to combine them into program. the desired final program, which is also saved. To try out the program, it is only necessary to select A thumbnail sketch scarcely does justice to so useful the “Start” option from the “Run” menu to have it rap- a program as this. The purpose of this review, idly compiled to memory and then run. The code however, is to interest those who have already used the should he saved on disk before taking this step, as it BASIC interpreter in something that is clearly better. could be lost if a serious error should cause the system From that standpoint, it may have been an injustice to to crash. If an error is encountered during compilation, give the impression that Microsoft QuickBASIC is the the offending statement is displayed, along with a de- only game in town. Borland’s Turbo BASIC is almost scription of the problem. Errors that come to light during as good (or perhaps it is to be consideredslightly better, compilation are called compile-time errors ,and are clas- depending on which one the reader has used the most). sified either as ”warning errors” or as “fatal errors.” The two compilers are very similar; therefore, much The latter kind prevent the program from running prop- of what has been written here applies to either one. erly and must be corrected. While the former may not Only QuickBASIC provides access to a detailed manual be that serious, it does pay to correct them. As ‘an ex- on screen. It compiles rather more slowly than Turbo ample, failure to DIMension a variable array will cause BASIC, but (in most cases, at least) produces a slightly a warning error message to be generated. If the subscript faster, slightly smaller, compiled program. Each com- is never likely to exceed 10 when the program is run- piler has its own devotees, and each is available for a ning, that error can safely be ignored. However, if the very modest expenditure. Either one provides a func- number of variables in that array should exceed 10 at tional alternative to the primitive capabilities of inter- any time when the program is run,execution will come pretive BASIC, and at a bargain price. to an abrupt conclusion with the display of an error message. This can be avoided by making it a routine to DIMension all arrays. John Case, Gamma Biologicals, Inc, 3700 Mangum Run-time errors can be difficult to locate for correc- Road, Houston, TX 77092. tion. This process is simplified by the compiler’s built-in debugger, which can be used to watch the changing values of selected variables as the program progresses. Execution of the program can be traced statement by statement, and breakpoints can be inserted to bring the program to a temporary standstill. The debugger can also be used to back up over the last 20 statements exe- cuted before a run-time error occurred. Program code written previously can be loaded by choosing “Open program” at the “Edit” menu, which will automatically load not only the main module that was being worked on earlier hut also any other modules that were in memory with it when everything was last

VOLUME 5, NUMBER 1, 1989 17