holgrave
asked on
Update progressbar while file retireved via Inet control.
I currently use the Inet control to retrieve a file from the internet and it works great. But I wanted to make the interface more sophisticated and informative for the user and I wanted to use a progressbar and update it WHILE the file is retrieved to reflect, well, the progress of the file retrieval.
Is this possible with the Inet control - or do I need something more sophisticated to do what I need.
Here is the code I now use:
Inet.Execute , "GET " & strRemoteFileName & " " & strLocalFilePath & strLocalFileName
Is this possible with the Inet control - or do I need something more sophisticated to do what I need.
Here is the code I now use:
Inet.Execute , "GET " & strRemoteFileName & " " & strLocalFilePath & strLocalFileName
see http://www.vbip.com/itc/itc-http-progress-02.asp
ASKER
Thanks for the example.
Our Execute methods are different, but I think this is because they are using the HTTP protocol while I am using FTP.
I have:
Inet.Execute , "GET " & strRemoteFileName & " " & strLocalFilePath & strLocalFileName
They have:
Inet1.Execute Trim$(txtURL.Text), "GET"
I have very similar code to that shown on VBIP in my StateChanged event. However it only gets called after my 'Execute Get' statment has completed. The Get statement seems to occur Asyncronously - ie. nothing else happens on my system until the full file transfer has completed. (It will loop round in a 'Inet.StillExecuting' loop but that is all it will do).
-------------------------- ---------- ---------- ---------- ----
Inet.Execute , "GET " & strRemoteFileName & " " & strLocalFilePath & strLocalFileName
Do Until Inet.StillExecuting = False
DoEvents
Loop
'Do something with the downloaded file.
-------------------------- ---------- ---------- ---------- ----
I have to put the 'StillExecuting statement in otherwise the proggy will try to do something with the file before it has fully downloaded.
This is what I have in my StateChanged event:
Private Sub Inet_StateChanged(ByVal State As Integer)
Select Case State
Case icResponseReceived ' 8
Case icResponseCompleted '12
Dim intFreeFile As Integer
Dim vtData As Variant ' Data variable.
Dim bDone As Boolean: bDone = False
intFreeFile = FreeFile
Open "C:\test.mdb" For Binary Access Write As intFreeFile
' Get first chunk.
vtData = Inet.GetChunk(1024, icByteArray)
DoEvents
' Get next chunk/s.
Do While LenB(vtData) > 0
Put intFreeFile, , vtData
vtData = Inet.GetChunk(1024, icByteArray)
Loop
Put intFreeFile, , vtData
Close intFreeFile
Case icError
Case 11 'unable to connect to remote host
End Select
End Sub
But StateChanged never occurs until the StillExecuting loop has finished.
Our Execute methods are different, but I think this is because they are using the HTTP protocol while I am using FTP.
I have:
Inet.Execute , "GET " & strRemoteFileName & " " & strLocalFilePath & strLocalFileName
They have:
Inet1.Execute Trim$(txtURL.Text), "GET"
I have very similar code to that shown on VBIP in my StateChanged event. However it only gets called after my 'Execute Get' statment has completed. The Get statement seems to occur Asyncronously - ie. nothing else happens on my system until the full file transfer has completed. (It will loop round in a 'Inet.StillExecuting' loop but that is all it will do).
--------------------------
Inet.Execute , "GET " & strRemoteFileName & " " & strLocalFilePath & strLocalFileName
Do Until Inet.StillExecuting = False
DoEvents
Loop
'Do something with the downloaded file.
--------------------------
I have to put the 'StillExecuting statement in otherwise the proggy will try to do something with the file before it has fully downloaded.
This is what I have in my StateChanged event:
Private Sub Inet_StateChanged(ByVal State As Integer)
Select Case State
Case icResponseReceived ' 8
Case icResponseCompleted '12
Dim intFreeFile As Integer
Dim vtData As Variant ' Data variable.
Dim bDone As Boolean: bDone = False
intFreeFile = FreeFile
Open "C:\test.mdb" For Binary Access Write As intFreeFile
' Get first chunk.
vtData = Inet.GetChunk(1024, icByteArray)
DoEvents
' Get next chunk/s.
Do While LenB(vtData) > 0
Put intFreeFile, , vtData
vtData = Inet.GetChunk(1024, icByteArray)
Loop
Put intFreeFile, , vtData
Close intFreeFile
Case icError
Case 11 'unable to connect to remote host
End Select
End Sub
But StateChanged never occurs until the StillExecuting loop has finished.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
navstar16 - will you marry me?
ASKER
Err, in other words thanks for the link.
I had searched VBIP, CodeHound, DeveloperDex etc. and came to the conclusion that it is only possible to show the progress with the GET command (while recieveing) with a SIZE command, to determine the size of the file you are going to download and then using the following syntax:
Inet.Execute , "GET " & strRemoteFileName & " " & strLocalFilePath & strLocalFileName
Do Until Inet.StillExecuting = False
If fso.FileExists(strLocalFil ePath & strLocalFileName) Then
Set file = fso.GetFile(strLocalFilePa th & strLocalFileName)
sngFileCompleted = file.size
progressbar.value = sngFileSize/sngFileComplet ed
End If
DoEvents
Loop
However I couldn't get this to work in reverse (using PUT ie. uploading a file to the server) as the FTP SIZE command was only returned after the PUT completes!
So looks like Inet is too lame for this. A Wininet solution is more appropriate.
Hence your link navstar16 - to a WinInet example that works great.
Job done!!
I had searched VBIP, CodeHound, DeveloperDex etc. and came to the conclusion that it is only possible to show the progress with the GET command (while recieveing) with a SIZE command, to determine the size of the file you are going to download and then using the following syntax:
Inet.Execute , "GET " & strRemoteFileName & " " & strLocalFilePath & strLocalFileName
Do Until Inet.StillExecuting = False
If fso.FileExists(strLocalFil
Set file = fso.GetFile(strLocalFilePa
sngFileCompleted = file.size
progressbar.value = sngFileSize/sngFileComplet
End If
DoEvents
Loop
However I couldn't get this to work in reverse (using PUT ie. uploading a file to the server) as the FTP SIZE command was only returned after the PUT completes!
So looks like Inet is too lame for this. A Wininet solution is more appropriate.
Hence your link navstar16 - to a WinInet example that works great.
Job done!!
ASKER
Thank you.
ASKER
Oops, spoke too soon.
Just compiled and run the example and it work GREAT (better than any other example I have ssen yet) - BUT it only covers DOWNLOADS, not UPLOADS.
I'm not to familiar with the WinInet API.
Does anyone with a brain the size of a planet know how to modify the example so it works with UPLOADS too.
I have dropped a line to Randy Birch....may be he will come back to me and I can pass on any hints he give...
Just compiled and run the example and it work GREAT (better than any other example I have ssen yet) - BUT it only covers DOWNLOADS, not UPLOADS.
I'm not to familiar with the WinInet API.
Does anyone with a brain the size of a planet know how to modify the example so it works with UPLOADS too.
I have dropped a line to Randy Birch....may be he will come back to me and I can pass on any hints he give...
ASKER
I have found a total solution to this.
But it a WinSock implementation rather than Inet or WinInet. But who cares - it works great.
Here is the link.
http://www.vbip.com/winsock/winsock_ftp_client_01.asp
It is a full FTP Client application, but it demonstrates the showing of the progress of the upload or download of a file.
Great code.
But it a WinSock implementation rather than Inet or WinInet. But who cares - it works great.
Here is the link.
http://www.vbip.com/winsock/winsock_ftp_client_01.asp
It is a full FTP Client application, but it demonstrates the showing of the progress of the upload or download of a file.
Great code.