KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q59430: 3 Cases Where DIR$ Gives "Illegal Function Call" in BASIC 7.00

Article: Q59430
Product(s): See article
Version(s): 7.00 7.10 | 7.00 7.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | docerr | mspl13_basic
Last Modified: 8-JAN-1991

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

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

1. Invoking DIR$ for the first time without a filespec$ parameter
   causes an "Illegal Function Call" error.

2. If you invoke DIR$ with a filespec$ and no matching files are found
   (it returns a null string -- ""), if you then invoke DIR$ another
   time without the filespec$ parameter, you will receive an "Illegal
   Function Call" 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 "Illegal Function
   Call." 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.

This information applies to Microsoft BASIC Professional Development
System (PDS) Versions 7.00 and 7.10 for MS-DOS and MS OS/2.

The code example below demonstrates that when DIR$ is used
incorrectly, it generates an "Illegal Function Call." 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$("*.*")
   count = 0
   WHILE temp$ <> "" ' 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
                    ' "Illegal Function Call" to occur.
   END

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.