Article ID: 192304
Article Last Modified on 6/29/2004
*-- Code begins here.
CLEAR
*-- Check if floppy drive a: is available for writing
*-- and print the results. Try this twice, once with
*-- a write-protected floppy and again with a floppy
*-- that is not write-protected.
? CheckMediaWrite("a:")
*-----------------------------------------------------------------
*- Function: CheckMediaWrite
*- Summary: Checks if the passed drive is available for writing.
*- Parameters: lsDrive - The drive to check.
*- Returns: -1 If drive cannot be written to.
*- Example: liReturn = CheckWrite("a:")
*-----------------------------------------------------------------
FUNCTION CheckMediaWrite()
PARAMETERS lsDrive
*-- Defines from Winbase.h
#DEFINE SEM_FAILCRITICALERRORS 0x0001
#DEFINE SEM_NOGPFAULTERRORBOX 0x0002
#DEFINE SEM_NOALIGNMENTFAULTEXCEPT 0x0004
#DEFINE SEM_NOOPENFILEERRORBOX 0x8000
*-- Check that the parameter is in the correct format.
IF SUBSTR(lsDrive, 2, 1) <> ":" OR ;
(ASC(UPPER(SUBSTR(lsDrive, 1, 1))) < 65 OR ;
ASC(UPPER(SUBSTR(lsDrive, 1, 1))) > 90)
=MESSAGEBOX("Drive must be in the format <drive letter>:", ;
0, "Error")
RETURN -1
ENDIF
*-- SetErrorMode determines whether the system handles
*-- serious errors or whether the program handles them.
DECLARE INTEGER SetErrorMode IN win32api INTEGER
*-- SetErrorMode returns to what the flags were last set.
*-- You need to store this in lnResult so that you can set them
*-- back the way they were before calling SetErrorMode.
*-- Failure to do so can produce unpredictable results
*-- when encountering future errors. SetErrorMode only
*-- applies to the current process and therefore only affects
*-- the FoxPro program that called SetErrorMode.
lnResult = SetErrorMode(SEM_FAILCRITICALERRORS)
hFile = FCREATE(lsDrive + "\tmp.txt")
IF hFile <> -1
FCLOSE(hFile)
ERASE(lsDrive + "\tmp.txt")
ENDIF
*-- Put things back the way you found them.
lnResult = SetErrorMode(lnResult)
RETURN hFile
*-- Code ends here.
A -1 appears on the desktop.
Additional query words: kbVFp600 kbVFp500a kbVFp500 kbAPI
Keywords: kbhowto kbcode KB192304