Movian
12-05-2008, 11:54 AM
Hey,
i found the following code that allows for the download of a file in the background using Winhttp. I have a button on a form that begins the process. What i would LIKE to do is setup a progress bar (two rectangles, 1 blue and i just gradually increase the width). However i am at a loss how to keep track of the download speed to convert to a width increment... any suggestions as always are GREATLY appreciated.
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object
On Error Resume Next
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
If Err.Number <> 0 Then
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
End If
On Error GoTo 0
MyFile = "http://www.exampleURL.com/Upgrade.exe"
WHTTP.Open "GET", MyFile, False
WHTTP.Send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing
FileNum = FreeFile
Open CurrentProject.path & "\Upgrade.exe" For Binary Access Write As #FileNum
Put #FileNum, 1, FileData
Close #FileNum
MsgBox "Download Complete"
ShellExecute 1, "open", CurrentProject.path & "\Upgrade.exe", "", CurrentProject.path, "1"
DoCmd.Quit acQuitSaveAll
For those who are interested this is in conjunction with my previous question regarding table updating. I have a mysql database on the web that stores the current version number. When we release an update we increment that number and Our program checks the number and if it is lower than the current number prompts the user that a new version is available. Then it asks if they wish to download it, if they select yes it activates this sub and downloads the upgrade.exe (a self extracting silent rar file that automaticly launches and upgrade.accdb file) runs the file and quits the main database. This progress bar would let the user know how long it will take to download the update as it can be up to 50 MB and on slower connections that can take a while.
i found the following code that allows for the download of a file in the background using Winhttp. I have a button on a form that begins the process. What i would LIKE to do is setup a progress bar (two rectangles, 1 blue and i just gradually increase the width). However i am at a loss how to keep track of the download speed to convert to a width increment... any suggestions as always are GREATLY appreciated.
Dim FileNum As Long
Dim FileData() As Byte
Dim MyFile As String
Dim WHTTP As Object
On Error Resume Next
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5")
If Err.Number <> 0 Then
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
End If
On Error GoTo 0
MyFile = "http://www.exampleURL.com/Upgrade.exe"
WHTTP.Open "GET", MyFile, False
WHTTP.Send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing
FileNum = FreeFile
Open CurrentProject.path & "\Upgrade.exe" For Binary Access Write As #FileNum
Put #FileNum, 1, FileData
Close #FileNum
MsgBox "Download Complete"
ShellExecute 1, "open", CurrentProject.path & "\Upgrade.exe", "", CurrentProject.path, "1"
DoCmd.Quit acQuitSaveAll
For those who are interested this is in conjunction with my previous question regarding table updating. I have a mysql database on the web that stores the current version number. When we release an update we increment that number and Our program checks the number and if it is lower than the current number prompts the user that a new version is available. Then it asks if they wish to download it, if they select yes it activates this sub and downloads the upgrade.exe (a self extracting silent rar file that automaticly launches and upgrade.accdb file) runs the file and quits the main database. This progress bar would let the user know how long it will take to download the update as it can be up to 50 MB and on slower connections that can take a while.