CHDRIVE Statement ---------------------------------------------------------------------------- Action Changes the current drive. Syntax CHDRIVE drive$ Remarks The argument drive$ is a string expression that specifies a new default drive. It must correspond to an existing drive and must be in the range A to lastdrive, where lastdrive is the maximum drive letter you set in your CONFIG.SYS file. If you supply a null argument ("") for drive$, the current drive does not change. If the argument drive$ is a string, CHDRIVE uses only the first letter. If you omit drive$, BASIC generates the error message Expected. Expression (in QBX) or String expression required (outside of QBX). CHDRIVE is not case sensitive. "C" is the same as "c." See Also CHDIR, CURDIR$ Example The following example demonstrates use of the CHDRIVE statements. It calls a SUB procedure that evaluates a file specification and changes the currently logged drive if necessary. DECLARE SUB ChangeDataDrive (filespec$) ON ERROR RESUME NEXT filespec$ = "A." ChangeDataDrive filespec$ filespec$ = "C.\DOS" ChangeDataDrive filespec$ SUB ChangeDataDrive (filespec$) curdrive$ = LEFT$(CURDIR$, 2) ' Get the current drive. ' Determine if there is a drive name on the filespec. IF INSTR(1, filespec$, ".") = 2 THEN newdrive$ = LEFT$(filespec$, 2) ELSE newdrive$ = curdrive$ END IF ' Ensure that the new drive is different from the ' currently logged drive. IF newdrive$ <> curdrive$ THEN CHDRIVE newdrive$ ' It isn't, so change it. PRINT "Logged drive changed from "; curdrive$; " to "; newdrive$ ELSE ' It is, so don't change it. PRINT "New drive same as logged drive. No change occurred." END IF END SUB