Re: Need some help...

Tech-Archive recommends: Speed Up your PC by fixing your registry



I thought I'd take one step at a time Stephany :-)

Bruce... You've got it. And Stephany's first idea is another sensible and
common way to separate "process" from UI.

Rather than update a specific (and specifically named) UI element your
CompressFolder() procedure should raise an "I've processed one" event. You
may even opt to have it raise multiple events, "I've started", "I'm
processing" and "I'm done". Now watch... you (in one scenario) decide to
have a progress bar update, then you simply tell the progress bar to listen
for and react to "I'm processing" events. Every time it "hears" one it
moves the progress bar. In some other scenario you may decide to have the
words "Processing Folder <whatever>" appear in a label. So this time you
tell the label to listen to "I'm processing" events instead and write code
the UI code there. Nothing in the UI knows what CompressFolder does and
CompressFolder has no idea about forms, buttons and progress bars. Needless
to say you would name your events something more sensible than "I'm
processing" but that's what you're telling the event listeners.

Note that to get <whatever> (the folder name) to appear in an event handler
you will have to send that information along when you raise the event.
Again there is an entire event system available to us for doing exactly
this. You send any information that the UI needs to know about in the
"args" argument and an event handler will receive it.

Threading? When you have everything else working smoothly you might look
into it. There can be concurrency issues so you have to think it through.
The nice thing is (as Stephany ponts out) you can use the app while the
compressing is going on. You would have to make certain that nothing you do
interferes with the compressing operation while it is running. There are
ways this can be done and among them setting a "compressing" flag turns on
when the process starts and off when it is done. The rest of the app can
check the flag and disable various actions (when needed) with the most
obvious action to prevent being the "compress folders" option. :-)

Try the events thing it will amaze you.

Tom

"Stephany Young" <noone@localhost> wrote in message
news:e35Wl3ZIHHA.4384@xxxxxxxxxxxxxxxxxxxxxxx
Yes, That's exactly what Tom is saying and it's a good idea too.

If you're feeling bold, you could reduce the dependencies further by
raising events insteading of updating the UI elements directly. That would
mean that you could get even bolder and launch CompressFolder as a thread
and let your app get on with other stuff while the compression is
happening.

We'll make a half-decent programmer out of you yet :)


"Bruce W. Darby" <kracor@xxxxxxxxxxx> wrote in message
news:O8mdnVM0BPrLVRnYnZ2dnUVZ_smonZ2d@xxxxxxxxxxxxxx
Tom,

Always open to constructive opinions. :) If I'm understanding what you're
putting forth....

The procedure call would be something like...

CompressFolder(txtSelectDir.Text, txtWriteDir.Text)

And the resulting procedure would receive the information by the
following...

Private Sub CompressFolder(ByVal strSourceDir As String, ByVal
strTargetDir As String)

Then strSourceDir and strTargetDir would not need to be Dim'd as they
already contain the information required from the calling procedure?

"Tom Leylan" <tleylan@xxxxxxxxxx> wrote in message
news:ePVpMAZIHHA.960@xxxxxxxxxxxxxxxxxxxxxxx
May I make one small suggestion since you might be in the mood to tweak
it a bit at this time?

Reducing dependencies is a good goal to keep in mind and you've set up a
dependency here that is very easy to eliminate. The SourceDir and
TargetDir in your example are supplied by two components which "must" be
named what you have them named. Any attempt to use the CompressFolder()
routine in any other way will fail.

Simply modify CompressFolder() so that it accepts strSourceDir and
strTargetDir as parameters passed to it. The call will then supply the
.Text properties of your two textboxes (in your example) but it can be
used in other situations by simply passing two properly composed
strings. They don't have to be textboxes and they don't have to be named
what you have them named.

Tom


"Bruce W. Darby" <kracor@xxxxxxxxxxx> wrote in message
news:F-SdnY8ESPIBKxnYnZ2dnUVZ_o6gnZ2d@xxxxxxxxxxxxxx
Stephany,

I owe you a debt of gratitude. With your assistance, I was able to find
a way to do what I wanted to do, even though I don't consider myself a
developer by any mean's. I now have something I can take to work and
use to make things a bit easier on my techs. While I doubt that the
coding is all that elegant, here is the final sub that I was able to
come up with that is doing the job I need it to do. Again, thanks for
all the assistance. Happy Holidays.

Private Sub CompressFolder()
Dim strSourceDir As String = txtSelectDir.Text
Dim strTargetDir As String = txtWriteDir.Text
Dim _Folders As String() = Directory.GetDirectories(strSourceDir)
prbProgress.Minimum = 0
prbProgress.Maximum = CInt(_Folders.Length)
prbProgress.Step = 1









.


Quantcast