Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Error Handling

Hi all

The following code copys a file to a floppy disk

If Response = vbYes Then
FileCopy "c:\temp\Test1.txt", "a:\data_" & Format(Now, "yyyy-mm-dd HhNn") & ".txt"

End If

if there is no floppy disk in drive the program fails, not got much knwledge of error handling, any ideas how to:

Copy file to floppy
error - no floppy
if no disk msg box insert disk
[418 byte] By [mp_direct] at [2007-11-11 7:13:36]
# 1 Re: Error Handling
First, I think you have to assume that the floppy drive is either the A: or B: drive. The following can determine drive status:

http://www.freevbcode.com/ShowCode.asp?ID=70

As an option to FileCopy you may want to consider using the SHFileOperation API function calls to copy files:

http://vbnet.mvps.org/code/shell/shfileopadv.htm
pclement at 2007-11-11 17:27:19 >
# 2 Re: Error Handling
You may also wish to read about the On Error statement in VB's online help.
Phil Weber at 2007-11-11 17:28:16 >
# 3 Re: Error Handling
on error goto errsub
FileCopy ....
exit sub
errsub:
if err.number = 71 then ''' disk not ready
msgbox "please insert a floppy"
resume
else
''' do something else

Marco
mstraf at 2007-11-11 17:29:15 >