|
-
Nov 4th, 2001, 10:09 AM
#1
Thread Starter
Addicted Member
Dricing me nuts!!!!
I am trying to download a .dat file and save it in my computer by using the URLDownloadToFile API...here is the code I have....
VB Code:
Private Sub ListView1_DblClick()
On Error GoTo Resolve
Dow = URLDownloadToFile(0, "http://www.mysite.com/myfile.dat", "c:\myfile.dat", 0, 0)
Resolve:
MsgBox "File could not be downloaded", vbInformation
End Sub
Please help me.....
-
Nov 4th, 2001, 10:12 AM
#2
Lively Member
i prosume it fails? as you didnt say............
-
Nov 4th, 2001, 10:13 AM
#3
Thread Starter
Addicted Member
Yes, it fail...
-
Nov 4th, 2001, 11:42 AM
#4
PowerPoster
2 problems with that code.
Private Sub ListView1_DblClick()
On Error GoTo Resolve
Dow = URLDownloadToFile(0, "http://www.mysite.com/myfile.dat", "c:\myfile.dat", 0, 0)
'This should say: Call URLDownloadToFile(0, "http://www.mysite.com/myfile.dat", "c:\myfile.dat", 0, 0)
' All you were saying is Dow = the API. in order to execute the API you have to use the Call keyword. And unless you put an exit sub before your messagebox statement you are going to get the failed message every time. So add an exit sub message here.
Exit Sub
Resolve:
MsgBox "File could not be downloaded", vbInformation
End Sub
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Nov 4th, 2001, 11:47 AM
#5
PowerPoster
Originally posted by Arc
' All you were saying is Dow = the API. in order to execute the API you have to use the Call keyword.
No, what he's got is fine, Call is not needed
Dow will contain the return value from the API function, which in the case of dll functions is usually 0 if it succedeed, or non 0 if it didn't.
-
Nov 4th, 2001, 11:57 AM
#6
Frenzied Member
Here's some code from Matthew Gates that I modified for your situation.
Haven't tested it....Hope it works 
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
Private 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 ListView1_DblClick()
DownloadFile "http://www.mypage.com/myfile.dat", "c:\myfile.dat")
If Not DownloadFile then
MsgBox "File could not be downloaded", vbInformation
Exit Sub
End If
Open "C:\myfile.dat" For Input As #1
Text1.Text = Input(LOF(1), 1)
Close #1
End Sub
-
Nov 4th, 2001, 12:02 PM
#7
Frenzied Member
Lol 
If the there are NO problems with the download, it will still show the error message box because you forget the Exit Sub before the label 
So your code should be:
VB Code:
Private Sub ListView1_DblClick()
On Error GoTo Resolve
Dow = URLDownloadToFile(0, "http://www.mysite.com/myfile.dat", "c:\myfile.dat", 0, 0)
Exit Sub
Resolve:
MsgBox "File could not be downloaded", vbInformation
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
|