[Resolved] Still executing last request
I get the error when running the code below, both from the IDE and from the compiled exe. Running using the IDE and putting a breakpoint and then stepping it works fine.
So what's it waiting for? I've put 1 second delays all over the place to see what is causing the error...but still get the error :cry:
17/01/2006 01:14:45",35764,"Still executing last request","Dailytext_01 Function CheckIfFileExist
VB Code:
Public Function CheckIfFileExist(strRemoteFolder As String, strRemoteFile As String) As Boolean
Dim var_data As Variant
Dim str_data As String
Dim i%, strFtpFiles() As String
Dim blnExist As Boolean
On Error GoTo ErrorLog
Screen.MousePointer = vbHourglass
With Inet1
.Execute , strRemoteFolder
sngWait = SleepEx(1000, 1000)
.Execute , "DIR"
sngWait = SleepEx(1000, 1000)
var_data = .GetChunk(9, icString)
str_data = str_data & var_data
sngWait = SleepEx(1000, 1000)
str_data = Trim(str_data)
If str_data <> "<!DOCTYPE" Then
blnExist = True
'Exit For
End If
'use the following line only if you have to close connection
'''.Execute , "CLOSE"
End With
sngWait = SleepEx(1000, 1000)
DeleteUrlCacheEntry (Inet1.url & strRemoteFolder & "/" & strRemoteFile)
sngWait = SleepEx(1000, 1000)
CheckIfFileExist = blnExist
Screen.MousePointer = vbDefault
Exit Function
Any ideas...this is driving me mad!! :sick:
Re: Still executing last request
I'm not 100% sure but it would seem that the Inet control is still downloading a file when you call the CheckIfFileExist function for a second time....HTH :)
Re: Still executing last request
Ok, found which line is the problem...
VB Code:
With Inet1
.Execute , strRemoteFolder
sngWait = SleepEx(5000, 5000)
.Execute , "DIR"
sngWait = SleepEx(5000, 5000)
5 seconds should be more than enough time!!
Is there something else causing this?
Re: Still executing last request
instead of sleeping for 5 seconds, try a loop with a DoEvents call in it
Or trap the error being caused and retry on error.
Re: Still executing last request
You could use the below which will wait until the previous command has completed. again HTH :)
VB Code:
With Inet1
.Execute , strRemoteFolder
While .StillExecuting
DoEvents
Wend
.Execute , "DIR"
While .StillExecuting
DoEvents
Wend
var_data = .GetChunk(9, icString)
str_data = str_data & var_data
While .StillExecuting
DoEvents
Wend
str_data = Trim(str_data)
If str_data <> "<!DOCTYPE" Then
blnExist = True
'Exit For
End If
'use the following line only if you have to close connection
'''.Execute , "CLOSE"
End With
Re: Still executing last request
Right that solves the problem :)
But here's another one!!
The code doesn't really do as I want it. As directory listing isn't allowed on the server it just returns a 403 every time.
Can some one help me...I'm getting myself all in a twist....
What I need to do is:-
- Check on a server to see if a file exists, I know the name of the file, directory and even the contents (it's a .txt file).
As I said directory listing isn't allowed, but if the file is there it can be downloaded/read.
Thanks
Steve
Re: Still executing last request
Why not download the file (without checking if it exists) then once downloaded open it and do some validation on the data to ensure the file downloaded it correct.
eg. If i download a file from our site that doesn't exists the first line of the file downloaded reads "<html><head><title>Error 404</title>". This tells me an error has occured. HTH :wave:
Re: Still executing last request
With a bit of google and a bit of messing around.....
VB Code:
Public Function CheckIfFileExist(strRemoteFolder As String, strRemoteFile As String) As Boolean
Dim str_data As String
Dim blnExist As Boolean
On Error GoTo ErrorLog
Screen.MousePointer = vbHourglass
With Inet1
str_data = .OpenURL(.url & strRemoteFolder & "/" & strRemoteFile)
While .StillExecuting
DoEvents
Wend
End With
str_data = Trim(str_data)
If str_data = "January" Then
blnExist = True
End If
'use the following line only if you have to close connection
'''.Execute , "CLOSE"
DeleteUrlCacheEntry (Inet1.url & strRemoteFolder & "/" & strRemoteFile)
CheckIfFileExist = blnExist
Screen.MousePointer = vbDefault
Exit Function
ErrorLog:
Open App.Path & "\errorlog.txt" For Append As #1
Write #1, Format(Now, "C"), Err.Number, Err.Description, "Dailytext_01 Function CheckIfFileExist"
Close #1
Err.Clear
Resume Next
End Function