Move over Microsoft: here's Power BASIC. (evaluation)
by Tom Campbell
QuickBASIC isn't the only game in town, you know. There's an old new kid on the block, PowerBASIC 2.0, formerly Turbo Basic, and it merits the name. PowerBASIC is powerful in ways that its Microsoft rival doesn't even begin to touch. Turbo Basic was relased several years ago, then hung up to dry by Borland. While QuickBASIC was upgraded constantly--and with fabulous success--Turbo Basic was a forgotten stepchild.
Borland finally returned Turbo Basic to its original developer, Bob Zale (who formed Spectra Publishing in mid 1990); released what was to have been Turbo Basic version 2; and renamed it PowerBASIC 2.0.
It's a killer product. Faster than the QuickBASIC native-code compiler, blessed with some incredible array-handling features and unheard-of accuracy in its multitude of numeric formats, and sporting dozens more keywords than QuickBASIC, PowerBASIC is a real contender.
PowerBASIC has a ton of hot new features. My favorites are the new array features, which let you sort arrays of numbers or strings in a single instruction far faster than if you wrote a quick sort routine; the communications support, which raises the ceiling from DOS's poky 9,600 bps all the way up to 115,000 bps; units, which act somewhat like OBJ modules but with error checking and much greater speed; and USING$, which lets youformat strings as if you were running them through PRINT USING, copying the output to a string variable instead of the screen. Much easier to use than C's sprintf() but serving the same purpose, USING$ saves a lot of code in scree-intensive applications.
A state-of-the-art source debugger finally eliminates all those ugly PRINT statements you've been inserting in questionable areas of your programs. Conditional compilations, like C's $ifdef, lets you maintain several different versions of your program in the same file.
PEEK and POKE and cleverly extended to let you peek and poke strings (you can move whole screens with one instruction) and all types of numbers. Strings can fill all of memory, not QuickBASIC's paltry 60K, and they can be up to 32K long each.
High Finance
An incredibly comprehensive variety of numeric formats and calculation routines brings PowerBASIC well to the fore of BASICs for the PC, making it by far the best choice for financial calculations and those requiring high precision for scientific and engineering uses.
Round-off errors and low precision have always plagued computer users, resulting in frequent "that's not what I really meant" situations where accumulated round-off errors introduced by such innocent-seeming calculations as "1/3 of 100 expressed as a decimal value" can cause severe errors in a small number of repetitions.
You can choose 80x87 coprocessor support for top speed on those systems with a numeric coprocessor; emulation of the coprocessor on systems without it, a slower option but one that produces results identical to those on coprocessor-equipped systems; or procedural math, which runs faster tahn 80x87 emulation.
The 80-bit extended precision values far outstrip the 64-bit "currency" type in Microsoft's $500 BASIC 7.0, and there's nothing at all like it in QuickBASIC. It also appears to be much faster than BASIC 7.0 or QuickBASIC in arithmetic calculations.
I have a few nits to pick, but they're strictly with the integrated environment. While the online help is markedly improved from Turbo Basic, it needs examples and more See also links. The help system in general is a bit antiquated, although it would've been the cat's pajamas three years ago. The language itself, however, is a breathtaking achievement. I can't wait to see version 3, but I'm in no rush--the horde of new features in this version will keep me happy for a long time.
This month's program is called J for Jump. It's a shortcut for the CD command when you'd like to change to a directory on the path, even a directory on another drive. To use it, just enter
J partialsubdirectory
where partialsubdirectory is any sequence of letters that will identify the directory (which must be one of the directories on your PATH) uniquely. It can be any contiguous sequence of letters appearing anywhere in the name. For example, if your path is
PATH=C: \BIN;C: \DOS;C: \BAT;C:\ WORLD5;C: \ TC \BIN;C: \PCTOOLS;
you can get to the WORD directory with the command J 5 because only one directory in the path has a 5 in it. You could jump to the C: \PCTOOLS directory--even from a drive other than C--with the command J P because it's the only directory on the PATH with a P in it. So if you're in the D: \BUILDER directory and use the command J P, you're getting to the same place you'd otherwise have to type this to get to.
C: CD \PCTOOLS
If no directory on the path matches the name on the command line (that is, forms a superset of the set of characters on the command line), J prints a message saying so and quits, setting ERRORLEVEL to 1. Likewise, if you neglect to follow J with a partial directory name, you'll get an error message.
This month's program illustrates two unique PowerBASIC features, ChDrive() and local variables.
When J.BAS finds a directory matching your input and the directory contains a colon in position 2, J.BAS uses ChDrive() to log on to that drive. More interesting is the ParsePath$ function. ParsePath$ is given a string in the form of a PATH statement and an integer variable to track the current position in the string. It builds a directory name in the variable PPath$, then uses that as the return value.
Note that the variables PPath$, NextPos%, and NextChar$ are declared as local variables. Local variables can only be used inside the SUBs or FUNCTIONs in which they're declared. Long a principle in other programming languages such as Pascal and C, local variables serve an extremely important purpose; they let you form an airtight seal around variables used only in one routine. That way they can't get changed accidentally by other routines that happen to use the same name--any number of other SUBs and FUNCTIONs can use these same names without affecting those inside ParsePath$().
Because the only publicly visible variables ParsePath$() can change are its parameters, ParsePath$() is what's known as a reentrant routine. Even though the use of locals is one of the cornerstones of good programming, they're not a available in all versions of compiled BASIC. Type LOCAL in the QuickBASIC environment, for example, and then press F1. All you'll get is the message The LOCAL keyword is reserved for future use. Well, the future is now with PowerBASIC.