Results 1 to 3 of 3

Thread: FileCopy errors

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Location
    Brisbane, QLD, Australia
    Posts
    10

    Unhappy

    An error shows if trying to copy a file to my A:drive if there is no disk present. can someone tell me how to code the error so that it doesnt shut my application down.
    i am using the FileCopy function in vb5.

  2. #2
    Addicted Member
    Join Date
    Jan 2000
    Location
    Sydney, Australia
    Posts
    196

    on error...

    This is one way to do it:

    in the sub that tries to do the filecopy do this:

    This is off the top of my head - not from any code i have in front of me.

    on error goto MySub_Err 'MySub_Err can be anything

    ...


    ...

    MySub_Err:

    if err.number = <insert error number for disk not being present> then
    msgbox "insert a disk dude"
    end if


    this represents a basic way to catch an error in VB and so it doesnt crash. You don't really need the if statement but if you do not put it in it will execute that code on any error <not just when the disk is not present>. To find out what the error number is - go thru your code in debug mode and when the err is thrown - in the immediate window type:

    ?err.number

    this will tell you the number...


    hth

    [Edited by funkyd77 on 06-16-2000 at 01:18 AM]

  3. #3
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Code:
    Private Sub Command1_Click()
       On Error Goto Yer_Aving_A_Laugh
    
       FileCopy "C:\AFile.exe", "A:\AFile.exe"
    
    Yer_Aving_A_Laugh :
       If Err.Number = 71 then
          MsgBox "Disk not ready error shown - place a blloming disk in then !!!"
          End Sub
       End If
    End Sub
    Take a look at the search option for the forumns to look up "error handling". The error you get above has the error number as 71. You might run into other problems you might want to test for on this :
    • Is the disk write protected ?
    • Is the disk full

    For the moment, use the above with :
    Code:
    Yer_Aving_A_Laugh :
       Msgbox "Error number is : " & err.number & VBCrlf & _
       "Description : " & err.description 
       'This one will return a messagebox of the error number & description,
       'rather than crash your app, it just exits the SUB (procedure). ;)
    For your testing. Once you're happy that you've covered every angle (and you always miss some )
    You put all the errrors into one big select case statement so your app can't possibly crash....[can it?]
    Code:
    Yer_Aving_A_Laugh :
       Select Case err.number
              'check the number of the error...
       Case 0
              'Do something to encounter it...
       Case 1
              'Do something else...
       Case 2
              'Do something else...
       End Select
    Last edited by alex_read; Apr 12th, 2001 at 02:54 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width