Results 1 to 33 of 33

Thread: DownloadFile progress bar?

  1. #1

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611

    Question DownloadFile progress bar?

    I've been using the DownloadFile API ( http://www.vb-world.net/internet/tip501.html ) but need to put in a progress bar or download counter for those really big files. Any ideas?
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  2. #2
    TheSarlacc
    Guest

    i kinda have one idea...

    umm what u could do is grab the filesize of the file being downloaded somehow (i dont know how) and have a timer constantly check the length of the LOCALNAME file.

    this is sketchy, forgive me if it dont work

    Code:
    dim localname as string,ttlsize as long
    localname = "C:\windows\desktop\doc1.doc"
    ttlsize =  <dont know how to do this!>
    progressbar1.max = 100
    timer1.interval = 250
    
    private sub timer1_timer()
       sizesofar = filelen(localname)
       progressbar1.value = (ttlsize / 100) * sizesofar
    end sub

  3. #3
    Member davethebrat's Avatar
    Join Date
    Jul 2001
    Location
    Buffalo, NY
    Posts
    51
    I was woundering the same thing...please e-mail me ([email protected]) if anything comes up...

  4. #4
    Junior Member
    Join Date
    Jul 2001
    Posts
    16
    you can use the file system object in vb to get the size of the file.

    Private Sub Command1_Click()
    Dim fso As New FileSystemObject
    Dim fil As File
    Dim fils As Files

    Set fil = fso.GetFile("c:\serveranalyzerresults.txt")
    List1.AddItem fil.Size
    End Sub

    make sure you select ms scripting runtime in refferences in project menu

  5. #5

    Thread Starter
    Fanatic Member Kzin's Avatar
    Join Date
    Dec 2000
    Posts
    611
    Ok - I think that this does the job

    http://msdn.microsoft.com/library/de...OnProgress.asp
    Looking for a friendly intelligent chat forum? Visit the white-hart.net

  6. #6
    Gerco
    Guest
    Originally posted by Kzin
    Ok - I think that this does the job

    http://msdn.microsoft.com/library/de...OnProgress.asp
    And how would one go about implementing that?

  7. #7
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    Well kids I did some diggin,

    This seems to provide the answer... but I'm just not that well versed in classes and whatnot.

    http://www.domaindlx.com/e_morcillo/...ip.asp?tip=adl

    Does this help?

  8. #8
    Gerco
    Guest
    Yes it does!

    I was already starting to wrote that class myself, but I didn't feel like writing a .tlb. Now I won't have to to either!

  9. #9
    Gerco
    Guest
    Does anyone know how to register a friggin' typelib without writing a program to do it for me?

    You have REGSVR32.EXE for .dll's, but what for typelibs?

  10. #10
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    I am still totally confused about the typelib (I know it's a type library... but what does that do?). Can any explain how this works in providing that function?

  11. #11
    Gerco
    Guest
    OK, I have completed a program to download some files with URLDownloadToFile with a progressbar and abort function.

    Basically, the typelib allows you to say:
    VB Code:
    1. Implements IBindStatusCallBack
    Then you must implement all methods of that interface, no problem, you only need to put code in one of them: IBindStatusCallBack_OnProgress(), here's how I did it.
    VB Code:
    1. Private Sub IBindStatusCallback_OnProgress(ByVal ulProgress As Long, ByVal ulProgressMax As Long, ByVal ulStatusCode As olelib.BINDSTATUS, ByVal szStatusText As Long)
    2.     #If fDEBUG = True Then
    3.         Static id As Long
    4.         id = id + 1
    5.         Debug.Print "[" & id & "] Progress event received: " & ulProgress & " of " & ulProgressMax & ", StatusCode: " & ulStatusCode
    6.     #End If
    7.     Dim bs As Single, ks As Integer
    8.     If ulProgress = 0 Then
    9.         tStartDownload = Timer
    10.     Else
    11.         bs = ulProgress / (Timer - tStartDownload)
    12.     End If
    13.     If bs > 0 Then ks = bs \ 1024 Else ks = 0
    14.     pbrFile.Min = 0
    15.     pbrFile.Max = 100
    16.     pbrFile.Value = CInt(100 * (ulProgress / ulProgressMax))
    17.     pbrFile.ToolTipText = ulProgress & " / " & ulProgressMax & " @ " & ks & "KB/s"
    18.     DoEvents
    19. End Sub

  12. #12
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    Ok... thanks, I am understanding it (kinda) now. When you are through could you post your project here so I can take a look at it?

    Basically I want to see where I have to put that subroutine and also do I have to put that entire typelib file in my project (what about space concerns?) or can I just put only the part I need?

  13. #13
    Gerco
    Guest
    Originally posted by davem
    also do I have to put that entire typelib file in my project (what about space concerns?) or can I just put only the part I need? [/B]
    You need to register the TypeLib, using regtlib.exe, which comes with VB. Then reference it (Project -> References).

    I don't believe you need to distribute the typelib with the compiled program, but I'm not 100% sure of that. VB should just take the part it needs and compile it into your program. You should not need the .TLB file.

    For an example, look at this AsyncDownload class.

  14. #14
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    Ok, I saw the sample code and I did the references and stuff and I have stared at that class file till I'm blue in the face. I am new to this stuff so could you guys make a simple project file that uses the DownloadFile API to get a file, and this other typelib crap to display the progress bar? This would be soooooo much appreciated!

  15. #15
    Gerco
    Guest
    Here you go, as simple as I could make it. Just type a URL in the box (or leave it as-is, the file is 5MB) and click download.

    Click abort to stop downloading, click quit to quit.

    I didn't even add a progress bar, but instead I have a listbox that lists the progress events as they come in.

  16. #16
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    Great... that helped immensely.

    So the Implements IBindStatusCallback means that we use the code for IBindStatusCallback that's in the typelib (which I take it is a kind of module with code in it) in our project.

    See the main thing I was confused with was how the OnProgress event get's called (since it isn't called from within our program). Does the code in the typelib tell that event to run... or Windows API just sending it messages?

    Anyways... thanks alot for all the help.

  17. #17
    Gerco
    Guest
    Originally posted by davem
    [B]Great... that helped immensely.

    So the Implements IBindStatusCallback means that we use the code for IBindStatusCallback that's in the typelib (which I take it is a kind of module with code in it) in our project.
    Close, but not really. The typelib doesn't contain ANY code. It merely tells anyone who wants to know that anything that Implements IBindStatusCallback has a number of functions (like OnProgress), nothing else. It only tells other programs how to use yours.
    See the main thing I was confused with was how the OnProgress event get's called (since it isn't called from within our program). Does the code in the typelib tell that event to run... or Windows API just sending it messages?
    Since there is no code in the typelib, windows calls our program. The typelib just tells windows WHAT part of the program to call (the OnProgresss event).

  18. #18
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    Finally got it! Thanks for bearing with me.

    So in general a typelib is kinda (and I use this analogy very, very loosely) like a constructor (for functions).

  19. #19
    Gerco
    Guest
    Originally posted by davem
    So in general a typelib is kinda (and I use this analogy very, very loosely) like a constructor (for functions).
    It's more like a contract. If I decide to write Inplements IBindStatusCallback in my class (form, whatever) I promise that my class or form will have all functions of that interface.

    The interface itself it nothing but a piece of paper, an agreement. If I implement it, someone else will know that my program had such&such functions, because I promised it would have by implementing the interface.

    It's more complicated than that, but I think this is a nice explanation.

  20. #20
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    That is a nice analogy. 'preciate it and take care.

    PS: One last annoying question (I promise): Do you know where I can get a list of what those codes mean... like Progress event recieved, code: 32, 0 / 0?

  21. #21
    Gerco
    Guest
    Originally posted by davem
    That is a nice analogy. 'preciate it and take care.

    PS: One last annoying question (I promise): Do you know where I can get a list of what those codes mean... like Progress event recieved, code: 32, 0 / 0?
    Open the Object Browser (F2?) and pick the lib 'olelib', then find BINDSTATUS in the left list and in the right list will be a listing of all values. You can see the numeric value of a constant bij selecting it and looking in the bottom box.

  22. #22
    Hyperactive Member davem's Avatar
    Join Date
    Dec 2000
    Location
    Gainesville, FL
    Posts
    265
    Ok Gerco... I lied!!!

    I got everything to work great (this was exactly what I wanted)... but check this post I wrote...

    Here's what the post says (I wrote you about this because I think the OnProgress event is causing this behavior!)

    http://forums.vb-world.net/showthrea...threadid=91353

    Alright... wierd deal.

    I have a public function on a form (a download progress form) that I call from another form. Now statements execute normally in that function... but if I click the close box the form unloads (I set the form = Nothing in the Form_Unload event) the statements still execute!

    Windows calls an IBindStatusCallback_OnProgress event repeatedly in my program. This might be why the statements in that function keep going even after I have unloaded it!

    What can I do to stop the rest of the statements in that function from executing after the form has been unloaded?

  23. #23
    Gerco
    Guest
    The answer is quite simple. Look at the example I gave you.

    When you click the close button (the X, I mean), the VB runtime calls Form_QueryUnload, in that function, I abort the download (if there is one and unload the form. If you don't abort the download, windows will re-load your form and execute the code in the OnProgress event.

    I had the same problem as you did, and this fixed it. ALWAYS! abort the current download before unloading your form, if you don't it will either be reloaded, or your program will go GPF. It's not a hard choice to make.

  24. #24
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Pittsburgh, PA
    Posts
    329
    to register the type library in windows98 using regtlib.exe, what file do i register? that tl_ole.msi file?
    ______________

  25. #25
    Gerco
    Guest
    Originally posted by HAVocINCARNATE29
    to register the type library in windows98 using regtlib.exe, what file do i register? that tl_ole.msi file?
    the .tlb file is what you need to register. But seeing that you have .msi file (MS Windows Installer file), you just need to execute it, it will probably register itself.

    If you cannot execute the file, go and download the Windows Installer redistributables at www.microsoft.com

  26. #26
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    I know this thread is like a yr and half old but...

    does anyone still have the type library / class ETC which was mensioned above?

    if so, could you post it / email me it please?

    w_pearsall [at] yahoo [dot] co [dot] uk

    Thanks
    Wayne

  27. #27
    New Member dougw's Avatar
    Join Date
    Jan 2003
    Location
    Ohio
    Posts
    12

    Anyone have the type library...

    The link provided in the thread no longer exists...
    http://www.domaindlx.com/e_morcillo...tip.asp?tip=adl

    Can someone post a new link to the type library that will allow you to reference the OnProgress method from IBindStatusCallback?

    The goal is to provide a progress bar while downloadinga file using URLDownloadToFile.
    Last edited by dougw; Aug 11th, 2003 at 10:30 AM.
    Programming today is a race between software engineers
    striving to build bigger and better idiot- proof programs,
    and the Universe trying to produce bigger and better idiots.

    So far, the Universe is winning.
    -- Rich Cook

  28. #28
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    Wayne

  29. #29
    New Member dougw's Avatar
    Join Date
    Jan 2003
    Location
    Ohio
    Posts
    12
    One last request....I have avoided using pointer in VB like the plauge...for obvious reasons.

    How do you pass the pointer to the caller's IBindStatusCallback interface? I have all the methods declared blank except OnProgress where I have the progress bar stuff...

    I cannot figure out how to get the reference to either IBindStatusCallback::OnProgress or just IBindStatusCallback for the last parameter in the URLDownloadToFile function.

    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

    lpfnCB
    Pointer to the caller's IBindStatusCallback interface. URLDownloadToFile calls this interface's IBindStatusCallback::OnProgress method on a connection activity, including the arrival of data.
    Programming today is a race between software engineers
    striving to build bigger and better idiot- proof programs,
    and the Universe trying to produce bigger and better idiots.

    So far, the Universe is winning.
    -- Rich Cook

  30. #30
    Frenzied Member wpearsall's Avatar
    Join Date
    Feb 2002
    Location
    England / UK
    Posts
    1,065
    copy the two TLB files from the zip file, then in the downloads, theirs an accual download application, just mod-out the app to what u need, its all i did with my update prog..
    Wayne

  31. #31
    New Member dougw's Avatar
    Join Date
    Jan 2003
    Location
    Ohio
    Posts
    12
    Humm...the zip file that I downloaded does contain the TLB files, but the samples directory within the ZIP does not have a download example.

    This is the list of sample applications:
    • ActiveDesktop
      ComponentCategoriesMgr
      Context Menu
      Extents
      Invoke sample
      Specify Property Pages
      TypeInfo sample
      TypeInfo Sample 2
    Programming today is a race between software engineers
    striving to build bigger and better idiot- proof programs,
    and the Universe trying to produce bigger and better idiots.

    So far, the Universe is winning.
    -- Rich Cook

  32. #32
    New Member dougw's Avatar
    Join Date
    Jan 2003
    Location
    Ohio
    Posts
    12

    Exclamation Got it working!

    I am guessing that you (wpearsall) were talking about the site:
    Edanmo's MVPS VB Site
    I saw his AsnycDownload and worked from that...

    Here is the class module that I am using along with the TLBs (olelib.tlb and olelib2.tlb)...
    Code:
    Option Explicit
    
    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
    '
    ' Implement IBindStatusCallback to receive
    ' the data and progress notification
    Implements IBindStatusCallback
    
    Function download(source As String, dest As String) As Long
        Dim rc As Long
        rc = URLDownloadToFileW(Me, source, dest, 0, Me)
    End Function
    
    Private Sub IBindStatusCallback_OnProgress(ByVal ulProgress As Long, ByVal ulProgressMax As Long, ByVal ulStatusCode As olelib.BINDSTATUS, ByVal szStatusText As Long)
        frmDownload.ProgressBar1.Min = 0
        frmDownload.ProgressBar1.Max = 100
        frmDownload.ProgressBar1.Value = CInt(100 * (ulProgress / ulProgressMax))
    End Sub
    
    Sub IBindStatusCallback_GetBindInfo( _
       grfBINDF As olelib.BINDF, _
       pbindinfo As olelib.BINDINFO)
       ' Not used
    End Sub
    
    Function IBindStatusCallback_GetPriority() As Long
       ' Not used
    End Function
    
    Sub IBindStatusCallback_OnStartBinding( _
       ByVal dwReserved As Long, _
       ByVal pib As olelib.IBinding)
       ' Not used
    End Sub
    
    Sub IBindStatusCallback_OnDataAvailable( _
       ByVal grfBSCF As olelib.BSCF, _
       ByVal dwSize As Long, _
       pformatetc As olelib.FORMATETC, _
       pstgmed As olelib.STGMEDIUM)
       ' Not used
    End Sub
    
    Sub IBindStatusCallback_OnLowResource( _
       ByVal reserved As Long)
       ' Not used
    End Sub
    
    Sub IBindStatusCallback_OnObjectAvailable( _
       riid As olelib.UUID, _
       ByVal punk As stdole.IUnknown)
       ' Not used
    End Sub
    
    Sub IBindStatusCallback_OnStopBinding( _
       ByVal hresult As Long, ByVal szError As Long)
       ' Not used
    End Sub
    The form (frmDownload) contains 2 text boxes (Source URL and Destination file), a command button to call the download function from the class and the progress bar.
    Programming today is a race between software engineers
    striving to build bigger and better idiot- proof programs,
    and the Universe trying to produce bigger and better idiots.

    So far, the Universe is winning.
    -- Rich Cook

  33. #33

    Re: DownloadFile progress bar?

    Quote Originally Posted by trjack52

    Code:
    HRESULT   hr;
    LPBINDSTATUSCALLBACK lpfnCB;
    Well im stuck on this one
    help me now i got a progress bar and im using an update option in my program

    These varibles are on the top:
    Lcc-win32/Visual Basic Code:
    1. HRESULT   hr;
    2. LPBINDSTATUSCALLBACK lpfnCB;

    im not sure if its correct

    ModifyProgressBar(PROGRESSHANDLE,TEXTTODRAWINBAR,DISPLAY %,DISPLAY CUSTOM TEXT); is from my dll differnt style to the progress bar mind

    still uses the same class just sends a pain message;

    and:
    Lcc-win32 Code:
    1. hr = URLDownloadToFile(0,urlname,"UPDATER.INI",1,0);
    2.                 if(hr==S_OK){
    3.                     ModifyProgressBar(hPB,"File status ",1,1);
    4.                     SendMessage(hPB, PBM_SETPOS, (WPARAM) 100, 0) ;
    5.                 }else{
    6.                     ModifyProgressBar(hPB,"File status ",1,1);
    7.                     SendMessage(hPB, PBM_SETPOS, (WPARAM) 0, 0) ;
    8.                 }

    ^ ok it works but i can do more

    Ok insted of it going to 100% and thats it no ACTUWAL percent i need an actuwall download here

    Lcc-win32 Code:
    1. ModifyProgressBar(hPB,"File status ",1,1);
    2.                     SendMessage(hPB, PBM_SETPOS, [FONT="Arial Black"][COLOR="Red"](WPARAM) 100[/COLOR][/FONT], 0) ;

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