Microsoft KB Archive/59430

= 3 Cases Where DIR$ Gives &quot;Illegal Function Call&quot; in Basic 7.00 =

Article ID: 59430

Article Last Modified on 10/20/2003

-

APPLIES TO


 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q59430



SUMMARY
Page 107 of the &quot;Microsoft Basic 7.0: Language Reference&quot; manual (for 7.00 and 7.10) incorrectly states that you can only receive &quot;Illegal Function Call&quot; using the DIR$ function if you don't specify a filespec$ the first time you call DIR$.

However, the DIR$ function returns an &quot;Illegal Function Call&quot; in the following three circumstances:


 * 1) Invoking DIR$ for the first time without a filespec$ parameter causes an &quot;Illegal Function Call&quot; error.
 * 2) If you invoke DIR$ with a filespec$ and no matching files are found (it returns a null string -- &quot;&quot;), if you then invoke DIR$ another time without the filespec$ parameter, you will receive an &quot;Illegal Function Call&quot; error. In other words, you must call DIR$ with a filespec$ until a match is found. After that, DIR$ can be called again with no filespec$ to get the next filename in the list of files found.
 * 3) Once the entire list of matched file names has been retrieved, using DIR$ without a filespec$ correctly returns a null string telling you that the end of the list has been reached. Invoking DIR$ one more time after that point generates an &quot;Illegal Function Call.&quot; In other words, once you run out of files that matched your original filespec$, you must call DIR$ with a filespec$ again until another match is achieved.



MORE INFORMATION
The code example below demonstrates that when DIR$ is used incorrectly, it generates an &quot;Illegal Function Call.&quot; If you comment out DIR$ after the WHILE loop, the program runs correctly.

The DIR$ function is a new function introduced in Microsoft Basic PDS 7.00. It is designed to let you find files and browse through directories looking for files without having to use SHELL, as in earlier versions of Basic. DIR$ takes a filespec$ parameter that is very similar to the parameters that can be passed to the DIR command found in MS-DOS or OS/2.

Code Example
DIM test(200) AS STRING * 12 CLS temp$ = DIR$(&quot;*.*&quot;) count = 0 WHILE temp$ <> &quot;&quot; ' When it returns null, ' the end of the list has been reached. test(count) = temp$ count = count + 1 PRINT temp$ temp$ = DIR$ WEND PRINT DIR$      ' If this line is left here, it will cause the error ' &quot;Illegal Function Call&quot; to occur. END

Additional query words: BasicCom

Keywords: KB59430

-

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

© Microsoft Corporation. All rights reserved.