HP Forums

Full Version: Sharp BASIC anomaly
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I stumbled upon something a bit strange playing around with few of my Sharp pockets.

The following code:

Code:
10 P$ = "PASSWORD"
20 IF P$ = "PASSWORD" THEN PRINT "CORRECT"

Executes correctly on PC-1500, however it fails on both EL-5500II and PC-G850VS. It appears the later two only recognize first seven characters in a string, despite being newer, so only the following works:

Code:
10 P$ = "PASSWORD"
20 IF P$ = "PASSWOR" THEN PRINT "CORRECT"

This might be a well-known fact, but figured I'd share as I found it interesting...
Correct, in most Sharps, the variables A-Z share the same (fixed) memory locations as A$-Z$, and thus the space for a float/numeric variable ends up being big enough to hold strings of 7 characters. (8 bytes each in most models, I believe.)

Later models (I think this includes your EL-5500II and PC-G850) can DIM larger strings, but they have to be declared as arrays (which can have just a single element if you wish).

e.g. DIM R$(0)*26 gives you an array R$ with one element (subscript 0) that will hold a string up to 26 characters in length. DIM NM$(10)*10 gives you an array with 11 elements (subscripts 0-10) that hold 10 characters each.

EDIT: And if you use "simple variables" (i.e. two-character variable names that are allocated dynamically upon use), those hold strings up to 16 characters in length. AA$="PASSWORD12345678" should work as expected.

The PC-1500 has a more traditional BASIC that dynamically allocates space for strings depending on length.
Thanks for a great explanation Dave, makes sense now!
Reference URL's