Results 1 to 4 of 4

Thread: Problem with error catching

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    145

    Problem with error catching

    Hi all... me again!!

    I am having trouble catching (or ignoring!) an error... Thsi is my code

    Code:
    'GET THE NEWS ROUTINE
    Private Sub getnews()
        On Error GoTo UploadError
        Inet1.AccessType = icUseDefault
        Inet1.URL = myftp
        Inet1.UserName = myusername
        Inet1.Password = mypassword
        Inet1.RequestTimeout = 40
        MsgBox "before kill"
        Kill "c:\news.mp3"     ' DELETE FILE BEFORE UPLOAD
        MsgBox "before get"
        Inet1.Execute , "get " & FileName & " " & destinationfolder & " " & FileName     ' D/L FILE
        MsgBox "after get"
        Do While Inet1.StillExecuting
          DoEvents
        Loop
       Inet1.Execute , "CLOSE"  ' CLOSE FTP CONNECTION
    UploadError:
        err_defined = "no"
        If Err.Number = "0" Then serverresult = "File downloaded correctly"
        If Err.Number = "35754" Then serverresult = "Unable to upload file, check password"
        If Err.Number = "35764" Then MsgBox "Server busy, please wait", , "Server Message"
        If Err.Number = "35752" Then MsgBox "Server Configuration Error, Check Config file", , "Server Message"
        If Err.Number = "12014" Then Beep
    End Sub
    So... my problem is that I want to ignore the file that is trying to be deleted if it does not exist, but I DO want to detect errors on the FTP part. There is celarly a conflict here as the on error line detects there is no file for the kill command and jumps stright to the upload errors ignoring the FTP get...

    Help?

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    145

    Re: Problem with error catching

    sorry, solved it, wasnt thinking !


    Code:
    'GET THE NEWS ROUTINE
    Private Sub getnews()
        On Error Resume Next
        Kill "c:\news.mp3"     ' DELETE FILE BEFORE UPLOAD
        On Error GoTo UploadError
        Inet1.AccessType = icUseDefault
        Inet1.URL = myftp
        Inet1.UserName = myusername
        Inet1.Password = mypassword
        Inet1.RequestTimeout = 40
        MsgBox "before kill"
        
        MsgBox "before get"
        Inet1.Execute , "get " & FileName & " " & destinationfolder & " " & FileName     ' D/L FILE
        MsgBox "after get"
        Do While Inet1.StillExecuting
          DoEvents
        Loop
       Inet1.Execute , "CLOSE"  ' CLOSE FTP CONNECTION
    UploadError:
        err_defined = "no"
        If Err.Number = "0" Then serverresult = "File downloaded correctly"
        If Err.Number = "53" Then MsgBox "Fiel error"
        If Err.Number = "35754" Then serverresult = "Unable to upload file, check password"
        If Err.Number = "35764" Then MsgBox "Server busy, please wait", , "Server Message"
        If Err.Number = "35752" Then MsgBox "Server Configuration Error, Check Config file", , "Server Message"
        If Err.Number = "12014" Then Beep
    End Sub

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Problem with error catching

    or better still to avoid the error by checking if the file exists first
    if len(dir("c:\news.mp3")) > 0 then Kill "c:\news.mp3"
    if you still get an error from the kill, it should not be ignored, as it may mean the file is open or something
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    145

    Re: Problem with error catching

    now you metnion it, the file being open is a possibility, and could be a problem, i'll try your suggestion, thanks!

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