B_Dorsey
asked on
Download Progress....
I have a Timer on my page that on interval of 500ms it checks the existence of a file being downloaded...
I call my Download code, and then the timer starts and checks the existence of the file first and then the filesize... I am passing the completed size to a function that the timer is calling every 500ms and do a simple math formula Round((CurrentFileSize / CompletedSize) * 100,0) to fill a progress bar up, but it seems that the timer doesnt run while the download is happening.... then all the sudden the progress bar goes all the way to the right and starts the next download.
(download code)
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
DownloadFile "http://www.mydomain.com/myzip.zip", "c:\downloads"
End Sub
I call my Download code, and then the timer starts and checks the existence of the file first and then the filesize... I am passing the completed size to a function that the timer is calling every 500ms and do a simple math formula Round((CurrentFileSize / CompletedSize) * 100,0) to fill a progress bar up, but it seems that the timer doesnt run while the download is happening.... then all the sudden the progress bar goes all the way to the right and starts the next download.
(download code)
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
Private Sub Form_Load()
DownloadFile "http://www.mydomain.com/myzip.zip", "c:\downloads"
End Sub
In .Net it's
Application.DoEvents()
Application.DoEvents()
ASKER
@lyonst
Where would I include this DoEvents? I have tried it before I call the download call and still the sme thing.
b
Where would I include this DoEvents? I have tried it before I call the download call and still the sme thing.
b
URLDownloadToFile is going to block and request to a block of code because it is a synchrounous function.
and = any*
ASKER
cant I change its async to false or something?
Have a look here
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=64914&lngWId=1
it uses The IBindStatusCallback events for URLDownloadToFile (lpfnCB)
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=64914&lngWId=1
it uses The IBindStatusCallback events for URLDownloadToFile (lpfnCB)
Can you include it in the timer
DownloadFile "http://www.mydomain.com/myzip.zip", "c:\downloads"
Just do this once at the start setting a flag not to execute it more then once.
Then include the update of the progress bar there with the DoEvents call?
DownloadFile "http://www.mydomain.com/myzip.zip", "c:\downloads"
Just do this once at the start setting a flag not to execute it more then once.
Then include the update of the progress bar there with the DoEvents call?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Take a look at http://www.mvps.org/emorcillo/download/vb6/adl.zip
Or, using standard IE dialog:
Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long
Public Sub DownloadFile(ByVal URL As String)
DoFileDownload StrConv(URL, vbUnicode)
End Sub
Private Sub Form_Load()
DownloadFile "http://www.mydomain.com/myzip.zip"
End Sub
Private Declare Function DoFileDownload Lib "shdocvw.dll" (ByVal lpszFile As String) As Long
Public Sub DownloadFile(ByVal URL As String)
DoFileDownload StrConv(URL, vbUnicode)
End Sub
Private Sub Form_Load()
DownloadFile "http://www.mydomain.com/myzip.zip"
End Sub
ASKER
Thanks for all the comments guys, appreciate all the help, although its kinda not pretty and hesitates a bit egl1044's answer provided me with a solution, I just needed a visible progress for my client, a hourglass wasnt enough and now they have a progress bar....
Thanks again for all the great suggestions.
b
Thanks again for all the great suggestions.
b
That will update the timeer control.