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?
Printable View
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?
umm what u could do is grab the filesize of the file being downloaded somehow (i dont know how) :rolleyes: 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
I was woundering the same thing...please e-mail me ([email protected]) if anything comes up...
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
Ok - I think that this does the job ;)
http://msdn.microsoft.com/library/de...OnProgress.asp
And how would one go about implementing that?Quote:
Originally posted by Kzin
Ok - I think that this does the job ;)
http://msdn.microsoft.com/library/de...OnProgress.asp
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?
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!
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?
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?
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:
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:
Implements IBindStatusCallBack
VB Code:
Private Sub IBindStatusCallback_OnProgress(ByVal ulProgress As Long, ByVal ulProgressMax As Long, ByVal ulStatusCode As olelib.BINDSTATUS, ByVal szStatusText As Long) #If fDEBUG = True Then Static id As Long id = id + 1 Debug.Print "[" & id & "] Progress event received: " & ulProgress & " of " & ulProgressMax & ", StatusCode: " & ulStatusCode #End If Dim bs As Single, ks As Integer If ulProgress = 0 Then tStartDownload = Timer Else bs = ulProgress / (Timer - tStartDownload) End If If bs > 0 Then ks = bs \ 1024 Else ks = 0 pbrFile.Min = 0 pbrFile.Max = 100 pbrFile.Value = CInt(100 * (ulProgress / ulProgressMax)) pbrFile.ToolTipText = ulProgress & " / " & ulProgressMax & " @ " & ks & "KB/s" DoEvents End Sub
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?
You need to register the TypeLib, using regtlib.exe, which comes with VB. Then reference it (Project -> References).Quote:
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]
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.
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! :D
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.
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.
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.Quote:
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.
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).Quote:
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?
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).
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.Quote:
Originally posted by davem
So in general a typelib is kinda (and I use this analogy very, very loosely) like a constructor (for functions).
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.
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.Quote:
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?
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?
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.
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.Quote:
Originally posted by HAVocINCARNATE29
to register the type library in windows98 using regtlib.exe, what file do i register? that tl_ole.msi file?
If you cannot execute the file, go and download the Windows Installer redistributables at www.microsoft.com
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 :)
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.
lol, its here:
http://www.mvps.org/emorcillo/
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.
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..
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
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)...
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.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
help me now i got a progress bar and im using an update option in my programQuote:
Originally Posted by trjack52
These varibles are on the top:
Lcc-win32/Visual Basic Code:
HRESULT hr; LPBINDSTATUSCALLBACK lpfnCB;
im not sure if its correct :eek2:
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:
hr = URLDownloadToFile(0,urlname,"UPDATER.INI",1,0); if(hr==S_OK){ ModifyProgressBar(hPB,"File status ",1,1); SendMessage(hPB, PBM_SETPOS, (WPARAM) 100, 0) ; }else{ ModifyProgressBar(hPB,"File status ",1,1); SendMessage(hPB, PBM_SETPOS, (WPARAM) 0, 0) ; }
^ 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 :D
Lcc-win32 Code:
ModifyProgressBar(hPB,"File status ",1,1); SendMessage(hPB, PBM_SETPOS, [FONT="Arial Black"][COLOR="Red"](WPARAM) 100[/COLOR][/FONT], 0) ;