Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Checking for Diskette in drive
Message
From
25/08/1999 22:16:55
 
 
To
25/08/1999 16:44:13
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00257624
Message ID:
00257725
Views:
19
Here you go!


* Function isdiskin - determine if a specified disk is present in
* FoxPro for Windows
*
* passed: drive letter, in the form of or
*
* returns: logical .t. if disk can be read, .f. if it cannot
*
* example:
* IF isdiskin("A:")
* WAIT WINDOW "There is a disk in drive A:"
* ENDIF

FUNCTION isdiskin

PARAMETERS m.drive

* test passed drive letter - is it greater than 2 characters,
* blank, or outside the range of A-Z? If so, then return .f.
m.drive = ALLTRIM(m.drive)
IF LEN(m.drive) > 2 .OR. LEN(m.drive) = 0 .OR. .NOT. ;
BETWEEN(ASC(UPPER(m.drive)), 65, 90)
RETURN .f.
ENDIF

IF RIGHT(m.drive,1) # ":"
m.drive = m.drive + ":"
ENDIF

* detect if FOXTOOLS.FLL is already loaded; if not, load it
m.isloaded = "FOXTOOLS" $ SET("LIBRARY")
IF .NOT. m.isloaded
SET LIBRARY TO SYS(2004)+"FOXTOOLS.FLL" ADDITIVE
ENDIF

* detect if another error routine is already present, save its name
m.olderror = ON('error')
ON ERROR DO diskerr

* hang onto the old error mode for later restoration
m.seterrmode = REGFN("SetErrorMode", "I", "I")

* SetErrorMode with an argument of 1 causes Windows to relinquish
* critical error handling back
* to the application, which ideally does a DOS
* GetExtendedErrorInformation call to determine
* the nature of the error. FoxPro doesn't do this, only recognizes
* that the error has occurred
* and so calls the ON ERROR routine with an error() value of 0.
m.olderrstate = CALLFN(m.seterrmode,1)

* default is no disk errors; our ON ERROR routine sets this variable
m.diskerr = .f.

* try to find the NUL file in the root of the passed drive
m.drivestate = FILE(m.drive + "\NUL")

IF .NOT. m.diskerr
* no disk error, so what did the file() call return?
IF m.drivestate
m.driveok = .t.
ELSE
m.driveok = .f.
ENDIF
ELSE
m.driveok = .f.
ENDIF

* restore the old error handler, old error state, old library state
* and old talk state
IF .NOT. EMPTY(m.olderror)
ON ERROR DO (m.olderror)
ELSE
ON ERROR
ENDIF

m.resterrstate = CALLFN(m.seterrmode,m.olderrstate)

IF .NOT. m.isloaded
RELEASE LIBRARY SYS(2004)+"FOXTOOLS.FLL"
ENDIF

RETURN m.driveok

* FoxPro thinks the error() is 0 after the failed file() call with
*SetErrorMode = 1. Just set
* our m.diskerr variable .t. on any error
PROCEDURE diskerr

m.diskerr = .t.

>Hi!
>I need a program to check for disk in drive A:>, sombody help me...
>thanks.
Previous
Reply
Map
View

Click here to load this message in the networking platform