Microsoft KB Archive/71525

= QuickBasic Program to Get Current Drive Using FILES & SCREEN =

Article ID: 71525

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 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 Q71525



SUMMARY
The program below uses error trapping, the FILES statement, and the SCREEN function to get the default (current) drive from a Microsoft QuickBasic program.

This information applies to Microsoft QuickBasic versions 4.00, 4.00b, 4.50; and to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS. The program will also work correctly in Microsoft Basic Professional Development System versions 7.00 and 7.10, but Basic PDS contains a CURDIR$ function that returns a string that can be parsed to get the current drive information without using the steps below.



MORE INFORMATION
The program below uses error trapping, the FILES statement, and the SCREEN function to get the current drive. In the program, the FILES statement displays the contents of a directory that does not exist. Because the FILES statement always displays a header of the current directory, we can then trap the error (error 53 -- &quot;File Not Found&quot;) that occurs when FILES tries to read the non-existent directory. Then we can use the SCREEN function to read the ASCII character indicating the current drive that FILES displayed on the screen before failing.

This method can be used as an alternative to the CALL INTERRUPT statement for determining the default drive. For more information on CALL INTERRUPT and determining the current drive, query on the following:

CALL and INTERRUPT and default and drive

Code Example:
ON ERROR GOTO Handler  'turn on an error handler LOCATE 5,1     'use LOCATE statement to position the cursor 'so you know where the FILES header is displayed. FILES &quot;\asdf#@jk&quot;  'look for a directory that cannot exist ON ERROR GOTO 0     'turn off the error handler LOCATE 10, 5: PRINT CurDrive$; &quot; is the current drive&quot; END

Handler: IF ERR = 53 THEN CurDrive$ = CHR$(SCREEN(5, 1))  'use SCREEN function to read ' ASCII character ELSE CurDrive$ = &quot;Error&quot;    'If error wasn't #53, then it is a                            'different error END IF   RESUME NEXT

Additional query words: QuickBas BasicCom

Keywords: KB71525

-

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

© Microsoft Corporation. All rights reserved.