Obtaining Current Drive Information with Microsoft Basic (62213)



The information in this article applies to:

  • Microsoft Visual Basic for MS-DOS
  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1

This article was previously published under Q62213

SUMMARY

Basic programs can call MS-DOS Interrupt 21h, function 19h to get the currently selected drive. Before calling this interrupt, AH (the upper byte of the AX register) must be set to 19h. The interrupt returns the number of the current drive in AL (the lower byte of the AX register). The drive numbers correspond to the letters of the alphabet (for example, 0 = A, 1 = B, etc.).

The information in this article is also included in the Help file provided with the Standard and Professional Editions of Microsoft Visual Basic for MS-DOS, version 1.0.

MORE INFORMATION

For more information on Interrupt 21h, function 19h, see Page 367 of "Advanced MS-DOS Programming, Second Edition," by Ray Duncan (Microsoft Press, 1988).

Note that the function "CURDIR$" can also be used to get the currently selected drive. However, using this method requires some string parsing. Although the code is smaller, it may be slower.

The following sample program reports the current drive:
' To try this example in VBDOS.EXE:
' 1. From the File menu, choose New Project.
' 2. Copy the code example to the Code window.
' 3. Press F5 to run the program.

' Use the following include file for Visual Basic for MS-DOS 1.0:
REM $INCLUDE: 'VBDOS.BI'
' Use the following include file for QuickBasic for MS-DOS:
' $INCLUDE: 'qb.bi'
' Use the following include file for Basic PDS for MS-DOS :
' $INCLUDE : 'qbx.bi'

   DIM Regs AS RegType

   ' Set AH to 19h.
   Regs.ax = &H1900
   ' Call the interrupt.
   CALL interrupt(&H21, Regs, Regs)

   ' Regs.ax must be ANDed with &HFF so that AH will be cleared.
   ' It must be cleared so the CHR$ function will be passed an
   ' ASCII code in the range of the letters A-Z (65-90).
   PRINT "The current drive is "; CHR$((Regs.ax AND &HFF) + 65)

   END
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB62213