|
-
Sep 13th, 2009, 01:59 PM
#1
Thread Starter
Addicted Member
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?
-
Sep 13th, 2009, 02:02 PM
#2
Thread Starter
Addicted Member
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
-
Sep 13th, 2009, 04:35 PM
#3
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
-
Sep 14th, 2009, 01:24 AM
#4
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|