3 Cases Where DIR$ Gives "Illegal Function Call" in Basic 7.00 (59430)



The information in this article applies to:

  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1

This article was previously published under Q59430

SUMMARY

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.

MORE INFORMATION

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
				

Modification Type:MajorLast Reviewed:10/20/2003
Keywords:KB59430