Andrew Keller was nice enough to work with me to get this working.
Since, after hours of looking, I couldn't find any examples of this
anywhere, I thought I would post it here for anyone in the future. This
is only a basic outline, but it might help.
This is a modified version of what Andrew sent, so if there's anything
wrong with it, it's probably my lack of skill. Please feel free to
offer suggestions.
Thanks, Andrew!
Dim source,dest As Folderitem
Dim sstream, dstream As BinaryStream
' don't forget to check for
' errors in source and dest
dest = volume(0).Child("DELETE")
source = volume(0).Child("delete.cab")
//open streams
sstream=source.OpenAsBinaryFile
dstream=dest.Child(source.Name).CreateBinaryFile(source.Name)
//set max of progress bar
sourceSize = sstream.length
//copy
While sstream.EOF=False
ProgressBar1.Maximum = ProgressBar1.width
dstream.Write sstream.Read(8192)
ProgressBar1.Value = (dstream.Length / sstream.Length) *
ProgressBar1.Maximum
StaticText1.Refresh
App.DoEvents
Wend
ProgressBar1.Value = 0
-----Original Message-----
From: gettingstarted-bounces at lists dot realsoftware dot com
[mailto:gettingstarted-bounces at lists dot realsoftware dot com] On Behalf Of
RBNUBE
Sent: Saturday, July 31, 2004 4:24 AM
To: 'Getting Started'
Subject: RE: ProgressBar
I appreciate the help, but I couldn't get it to work. Thanks anyway.
-----Original Message-----
From: Andrew Keller [mailto:andrew at kellerfarm dot com]
Sent: Thursday, July 29, 2004 2:38 AM
To: rbnube at mabenterprises dot com; Getting Started
Subject: Re: ProgressBar
> I know this has been covered before, but I'm not sure what I should
> do. I want to display a progress bar during a file copy. All of the
> examples I've seen accomplish this by reading the binary stream. This
> seems like overkill. Doesn't it make more sense to get the size of
> the file to be copied and then compare this to the size of the file
> that is copying?
>
Of the samples of code I'm thinking of, they are about the same.
>
> I've gathered that updating a progress bar should be done in a thread.
> How would I accomplish this?
>
In my opinion, putting the copying process in a thread can be a lot of
work in some cases, but is usually the best idea. Here is some code
that copies a file using a binary stream and displays the progress on a
progress bar:
Sub CopyFile(source As Folderitem, dest As Folderitem)
Dim i As Integer
Dim sstream, dstream As BinaryStream
' don't forget to check for
' errors in source and dest
//open streams
sstream=source.OpenAsBinaryFile
dstream=dest.Child(source.Name).CreateBinaryFile
//set max of progress bar
Window1.ProgressBar1.Maximum=sstream.Length
//copy
While sstream.EOF=False
dstream.Write sstream.Read(1024)
ProgressBar1.Value=dstream.Length
Wend
End Sub
This is the bare minimum, and with no error checking. Source should be
a file, and dest should be a folder. To check for copying errors, you
can compare the lengths of the binary streams after the While loop.
They should be the same. I also believe that in RB 5.5 there is now a
LastErrorCode property for binary streams.
Tip: when trying to access controls such as a progress bar from a
thread that are on a window that has been instanced (you have created a
new copy of the window), you can put a property in the thread that
points to the target window (for example, MyDisplayWindow As Window1).
Then, if you have the display window create the thread, then you can
call Thread.MyDisplayWindow=Self . If the display window does not
create the thread, then you can use the variable that you created the
window with. The code would then be:
Dim w As Window1
Dim t As MyThread
w=new Window1
t=new MyThread
t.MyDisplayWindow=w
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>
|