Changing this code so my application does not freeze?
VB 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.allapi.net", "c:\allapi.htm"
End Sub
My program downloads image after image... Some of the images are +1MBs... So they take +5 seconds to download, and when ever its downloading my whole application stops (cannot move the window, windows is not updated (if a other window goes over it, the window will only be updated once the image is done downloaded))....
So how would I change that code so my program works normally even when the image is downloading?
note: Its kind of like when you have a loop that takes forever, while vb is in the loop, you cannot do anything with the program (but in a loop you can use DoEvents)...
Re: Changing this code so my application does not freeze?
you would need to use Winsock instead.
example
http://www.vbforums.com/showpost.php?p=2537947
Re: Changing this code so my application does not freeze?
I dont know the first thing about winsock...
Re: Changing this code so my application does not freeze?
Any other suggestions? This bug is very annoying, and if I make this application public I will need to fix this...
Re: Changing this code so my application does not freeze?
Quote:
Originally Posted by Zeratulsdomain
Any other suggestions? This bug is very annoying, and if I make this application public I will need to fix this...
http://curl.haxx.se is a program I use for advanced downloading or website navigation...it *may* be of use to you...or you could write a program to call via the shell which downloads the file and lets the main program continue what it's doing...however, winsock is probably the best way to go, although I know nothing about winsock myself and can't stand the way it regularly crashes the VB IDE if you're not careful (you can't break out of a program while using winsock as it freezes the whole thing)...there's an alternative to winsock that some people here talked about, but I dunno the URL...I am sure someone will know the URL and will tell you :-)
Re: Changing this code so my application does not freeze?
You can use MS Internet Transfer Control:
VB Code:
Dim site As String
site = Inet1.OpenURL("http://www.allapi.net")
Open "c:\allapi.html" For Output As #1
Print #1, site
Close #1
MsgBox "Done!"
Re: Changing this code so my application does not freeze?
smUX: I am looking for a VB solution...
gavio: I use inet to get the source of my html.... But I remember I had tried it with images and had some sort of problem... What is the syntax for it again?
Isnt there some reliable way to download a file in VB while also getting info (like the download rate?)
Re: Changing this code so my application does not freeze?
Works for all files:
VB Code:
Option Explicit
Public i As Long
Private Sub Form_Load()
On Error GoTo errorHandeler
Dim strURL As String
Dim bData() As Byte
Dim intFile As Integer
strURL = "http://www.someSite.com/someFile.jpg"
intFile = FreeFile()
bData() = Inet1.OpenURL(strURL, icByteArray)
Open "C:\someFile.jpg" For Binary Access Write As #intFile
Put #intFile, , bData()
Close #intFile
Exit Sub
errorHandeler:
End Sub