Microsoft KB Archive/80411

= &quot;Illegal Function Call&quot; Using Asc with Uninitialized String =

Article ID: 80411

Article Last Modified on 8/16/2005

-

APPLIES TO


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

-



This article was previously published under Q80411



SUMMARY
If you try to use the Asc function on a string that has been initialized to a value of null (&quot;&quot;), you will correctly receive an &quot;Illegal function call&quot; error message. The string must be assigned to a value other than &quot;&quot; (the null string) for the Asc function to return the ASCII value of the first character in the string.



MORE INFORMATION
This information is documented in the QB.EXE 4.5 or QBX.EXE 7.0/7.1 online Help for the Asc function, but is not available when the error message is received when the Help option is chosen. Below are two code examples that reproduce the error. By assigning the string to any value, the Asc function works without error.

The following code examples will fail:

Code Error Example 1
PRINT ASC(x$)

Code Error Example 2
x$ = &quot;&quot; PRINT ASC(x$) The following code examples will work correctly:

Correct Code Example 1
x$=&quot; &quot; PRINT ASC(x$) Output: 32

Correct Code Example 2
x$=&quot;Pearl Jam&quot; PRINT ASC(x$) Output: 80

To work around the error, check the length of the string with the Len function in an IF...THEN statement to ensure it is greater than zero before passing the string as an argument to the Asc function. The following code example demonstrates the workaround. The code allows you to only use the Asc function when something has been assigned to the string, otherwise it sets the Asc value to zero. Assigning Temp$ to CHR$(0) returns a 0, but assigning it &quot;&quot; gives you an &quot;Illegal function call&quot;. If LEN(Temp$) > 0 THEN ' Use the Asc Function AscVal = ASC(Temp$) Else AscVal = 0 End if PRINT AscVal

Additional query words: QuickBas BasicCom 1.00 4.00 4.00a 4.00b 4.50 6.00 6.00b 7.00 7.10

Keywords: KB80411

-

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

© Microsoft Corporation. All rights reserved.