|
VFP 愛用者社區 本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
|
上一篇主題 :: 下一篇主題 |
發表人 |
內容 |
Ruey
註冊時間: 2003-03-12 文章: 1698 來自: tunglo
第 1 樓
|
發表於: 星期六 八月 30, 2003 1:29 pm 文章主題: 檢查磁碟機是否可讀(轉貼) |
|
|
How to check if drive is ready
Summary
It's a good idea to make sure that there's media in the removable drive before accessing it and display user friendly message instead of system error message if drive isn't ready. It can be done using Windows Scripting Host (WSH) or with help of Windows API.
Description
代碼: | Windows Scripting Host (WSH)
oFSO = CREATEOBJECT("Scripting.FileSystemObject")
oDrv = oFSO.GetDrive("A:")
? oDrv.IsReady
* You can also check if drive exists
? oFSO.DriveExists("A:") |
--------------------------------------------------------------------------------
代碼: | Windows API (based on mskb #Q191501)
#define SEM_FAILCRITICALERRORS 0x0001
*-- 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.
lnOldMode = SetErrorMode(SEM_FAILCRITICALERRORS)
*-- Test the FoxPro DISKSPACE() function. If you get a -1, then
*-- there is no disk in the drive.
IF DISKSPACE("a:") = -1
MESSAGEBOX("No disk present.", 0)
ENDIF
*-- Restore system error handling settings.
= SetErrorMode(lnOldMode)
|
_________________ #############################
快樂媽咪系列幸福宅配,喝十全雞湯~原來幸福那麼簡單!!
學會VFP使用者社區的搜尋,Code才會更有趣~
############################# |
|
回頂端 |
|
|
|
|
您 無法 在這個版面發表文章 您 無法 在這個版面回覆文章 您 無法 在這個版面編輯文章 您 無法 在這個版面刪除文章 您 無法 在這個版面進行投票 您 無法 在這個版面附加檔案 您 無法 在這個版面下載檔案
|
|