Results 1 to 7 of 7

Thread: Dricing me nuts!!!!

  1. #1

    Thread Starter
    Addicted Member kikelinus's Avatar
    Join Date
    Nov 2000
    Posts
    219

    Angry 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:
    1. Private Sub ListView1_DblClick()
    2.     On Error GoTo Resolve
    3.     Dow = URLDownloadToFile(0, "http://www.mysite.com/myfile.dat", "c:\myfile.dat", 0, 0)
    4.  
    5. Resolve:
    6.     MsgBox "File could not be downloaded", vbInformation
    7. End Sub

    Please help me.....

  2. #2
    Lively Member
    Join Date
    May 2001
    Location
    Leicester, UK
    Posts
    92
    i prosume it fails? as you didnt say............
    Damaskus

    Bored? Fed Up? Wanna play some games? then visit my website!
    Website:- www.gamesgalleon.com
    E-Mail:- [email protected]

  3. #3

    Thread Starter
    Addicted Member kikelinus's Avatar
    Join Date
    Nov 2000
    Posts
    219
    Yes, it fail...

  4. #4
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    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.


  5. #5
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    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.

  6. #6
    Frenzied Member
    Join Date
    Mar 2001
    Location
    You are HERE •™
    Posts
    1,300
    Here's some code from Matthew Gates that I modified for your situation.
    Haven't tested it....Hope it works

    VB Code:
    1. Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
    2. "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As _
    3. String, ByVal szFileName As String, ByVal dwReserved As Long, _
    4. ByVal lpfnCB As Long) As Long
    5.  
    6. Private Function DownloadFile(URL As String, _
    7.     LocalFilename As String) As Boolean
    8.     Dim lngRetVal As Long
    9.     lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    10.     If lngRetVal = 0 Then DownloadFile = True
    11. End Function
    12.  
    13. Private Sub ListView1_DblClick()
    14.     DownloadFile "http://www.mypage.com/myfile.dat", "c:\myfile.dat")
    15.  
    16.     If Not DownloadFile then
    17.         MsgBox "File could not be downloaded", vbInformation
    18.         Exit Sub
    19.     End If
    20.  
    21.     Open "C:\myfile.dat" For Input As #1
    22.         Text1.Text = Input(LOF(1), 1)
    23.     Close #1
    24.  
    25. End Sub

  7. #7
    Frenzied Member Jotaf98's Avatar
    Join Date
    Jun 2000
    Location
    I'm not gonna give you my IP address! Ok... Portugal, South-Western Europe, 3rd rock from the sun (our star is easy to find, a 47 Ursae Majoris in the Milky Way :p )
    Posts
    1,457
    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:
    1. Private Sub ListView1_DblClick()
    2.     On Error GoTo Resolve
    3.     Dow = URLDownloadToFile(0, "http://www.mysite.com/myfile.dat", "c:\myfile.dat", 0, 0)
    4.  
    5. Exit Sub
    6. Resolve:
    7.     MsgBox "File could not be downloaded", vbInformation
    8. End Sub
    Code:
    Temp = Me.GetIQ()
    'Error 9: Overflow
    'DON'T PANIC! :eek:

    To learn how to use realistic effects in your games like fire, rain, snow and magic effects, read my article on particles systems here.


    Jotaf's Theories!
    "Cats land on their feet. Toast lands peanut butter side down. A cat with toast strapped to its back will hover above the ground in a state of quantum indecision."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width