VAL("&H") and VAL("%") Unexpectedly Returning Nonzero Value (26931)
The information in this article applies to:
- Microsoft QuickBASIC 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBASIC 4.5
This article was previously published under Q26931 SYMPTOMS
When "&H", "&", and "%" are passed alone as arguments to the VAL
function, VAL returns 0 (zero) as expected in QuickBasic Version 3.00.
In QuickBasic Version 4.00, VAL returns a nonzero value for "&H" and
"&", and returns a "type mismatch" (error 5) at run time for "%". VAL
is expected to return 0 (zero) because "&H" is 0 in hexadecimal
notation, "&" is 0 in long integer notation, and "%" is 0 in integer
notation.
Passing "&H0" or "0%" to VAL returns 0 as expected.
STATUS
Microsoft has confirmed this to be a bug in QuickBasic Versions
4.00, 4.00b, and 4.50 and in Microsoft Basic Compiler Versions 6.00
and 6.00b (buglist6.00, buglist6.00b). This problem was corrected in
Microsoft Basic Professional Development System (PDS) Version 7.00 for
MS-DOS and MS OS/2 (fixlist7.00).
If your program accepts input into a string variable and then uses
VAL, you may want to filter out the character combinations that are
not accepted. On the Microsoft QuickBasic Versions 4.00 and 4.00b
Utilities and Examples Disk in the \Source subdirectory there is a
program called STRTONUM.BAS that filters out all characters from a
string except numeric digits, the decimal point, and a minus sign.
STRTONUM.BAS can be modified if you want to allow hexadecimal
constants but exclude the special cases "&H" and "H" that return
nonzero values from VAL. You can also write your own filtering
routine.
Modification Type: | Minor | Last Reviewed: | 1/9/2003 |
---|
Keywords: | KB26931 |
---|
|