'===========================================================================
' Subject: DRIVE CHANGE ROUTINE               Date: 06-07-98 (16:56)       
'  Author: Marc van den Dikkenberg            Code: QB                     
'  Origin: excel@xs4all.nl                  Packet: DOS.ABC
'===========================================================================
'-------------------------------------------------------------------------
' ChangeDrive for QuickBasic 4.5
' Public Domain, June 1998
' Created by Marc van den Dikkenberg
'
' The PowerBasic Archives -- http://www.xs4all.nl/~excel/pb.html
' All Basic Code Archives -- http://www.xs4all.nl/~excel/pbabc.html
'-------------------------------------------------------------------------

'$INCLUDE: 'qb.bi'

DIM SHARED InReg AS RegType
DIM SHARED OutReg AS RegType
DECLARE SUB CHDRV (drive AS STRING)

CLS

CHDRV "C"
CHDIR "\":  ' Change back to root, instead of current directory
FILES

END

SUB CHDRV (drive AS STRING)
   ' First check if the drive you want to access exists...
   '
   DIM drivename AS STRING * 4
   DIM buff AS STRING * 128
   drivename = UCASE$(LEFT$(drive, 1)) + ":\" + CHR$(0)
   InReg.AX = &H6000
   'InReg.DS = VARSEG(DriveName)
   InReg.SI = VARPTR(drivename)
   'InReg.ES = VARSEG(Buff)
   InReg.DI = VARPTR(buff)
   Interrupt &H21, InReg, OutReg
   '
   IF LEFT$(buff, 1) <> CHR$(0) THEN
      ' If the drive exists, change it to be the default drive.
      '
      DriveNumber% = ASC(UCASE$(LEFT$(drive$, 1))) - 65
      InReg.AX = &HE00
      InReg.DX = DriveNumber%
      Interrupt &H21, InReg, OutReg
'     PRINT OutReg.AX MOD 256: ' <-- returns the LASTDRIVE=.. Value
   ELSE
      ' If the drive does NOT exist, generate a "Path Not Found" error.
      ' Of course you can remove this error statement, and replace it
      ' with something of your own to tell the main program that the
      ' operation has failed.
      ERROR 76
   END IF
END SUB
