|
-
Aug 12th, 2006, 08:21 PM
#1
Thread Starter
Hyperactive Member
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)...
-
Aug 12th, 2006, 08:47 PM
#2
PowerPoster
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
Last edited by rory; Aug 12th, 2006 at 08:50 PM.
-
Aug 15th, 2006, 08:29 PM
#3
Thread Starter
Hyperactive Member
Re: Changing this code so my application does not freeze?
I dont know the first thing about winsock...
-
Aug 18th, 2006, 06:08 AM
#4
Thread Starter
Hyperactive Member
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...
-
Aug 18th, 2006, 06:14 AM
#5
PowerPoster
Re: Changing this code so my application does not freeze?
 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 :-)
Well, everyone else has been doing it :-)
Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
Expect more to come in future
If I have helped you, RATE ME! :-)
I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!
And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.
-
Aug 18th, 2006, 06:31 AM
#6
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!"
-
Aug 20th, 2006, 11:47 AM
#7
Thread Starter
Hyperactive Member
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?)
-
Aug 20th, 2006, 11:53 AM
#8
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|