Microsoft KB Archive/69162

= VAL Function Returns &quot;Type Mismatch&quot; for Some Invalid Numbers =

Article ID: 69162

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q69162



SUMMARY
The VAL function may return the error message &quot;Type mismatch&quot; in specific cases if the string value is not a valid number. In most other cases, VAL normally returns 0 (zero) for invalid numbers.

This information applies to Microsoft QuickBasic 4.00, 4.00b, and 4.50, to Microsoft Basic Compiler 6.00 and 6.00b, and to Microsoft Basic Professional Development System (PDS) 7.00 and 7.10.

Microsoft is researching this problem and will post new information here as it becomes available.



MORE INFORMATION
The VAL function returns the numeric value of a string expression that represents a number. VAL interprets the sequence of characters until a character is found that cannot be recognized as part of a number. If the string is not a valid number (such as a string of alphabetic characters), the VAL function returns zero. However, in certain cases, a string of alphabetic characters will return the &quot;Type mismatch&quot; error.

The problem often occurs with a string expression that starts out with a valid numeric expression, such as &quot;&&quot; (for example, &H for hexadecimal notation), &quot;-&quot; (for example, a negative number), or &quot;+&quot; (for example, a positive number), but follows that with an invalid character. When parsing such a string, the VAL function will encounter an invalid numeric format and give &quot;Type mismatch&quot; when it should return zero.

Examples
PRINT VAL(&quot;12.32&quot;)           '12.32 prints correctly PRINT VAL(&quot;s%k&r3ds&quot;)        '0 prints correctly PRINT VAL(&quot;&+%we3&quot;)       'Gives &quot;Type mismatch&quot;, but should be 0 The string expressions listed below generate the &quot;Type mismatch&quot; error when passed to the VAL function. This is not a complete list.

Each line in the table below shows combinations of characters, which are grouped by the following rules:

[] = Encloses symbol required to pass to VAL


 * = Logical or (separates choices in a list of characters)

char = CHR$(32) through CHR$(126)

real = A valid number which contains a decimal point

NULL = A byte value equal to 0 (zero)

integer = A valid number with no decimal point

List of known string of symbols: [ & | D | E | NULL ] +% [ NULL | char ] [ & | D | E | NULL ] +& [ NULL | char ] [ & | D | E | NULL ] +@ [ NULL | char ] [ & | D | E | NULL ] -% [ NULL | char ] [ & | D | E | NULL ] -& [ NULL | char ] [ & | D | E | NULL ] -@ [ NULL | char ]

[ + | - | . | integer | NULL ] .% [ NULL | char ] [ + | - | . | integer | NULL ] .& [ NULL | char ]

[ + | - | . | real | NULL ] D% [ NULL | char ] [ + | - | . | real | NULL ] D& [ NULL | char ] [ + | - | . | real | NULL ] D@ [ NULL | char ] [ + | - | . | real | NULL ] E% [ NULL | char ] [ + | - | . | real | NULL ] E& [ NULL | char ] [ + | - | . | real | NULL ] E@ [ NULL | char ]

[ . ][ real ][ % | & ] [ E | D ][ integer ][ % | & | @ ] For other examples where the VAL function gives a &quot;Type mismatch&quot; error, query on the following words:

Basic and VAL and type and mismatch

Additional query words: QuickBas BasicCom

Keywords: KB69162

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.