473,770 Members | 7,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need some help...

This will be my very first VB.Net application and it's pretty simple. But
I've got a snag in my syntax somewhere. Was hoping that someone could point
me in the right direction.

The history:
My work involves creating custom packages of our software product for golf
courses that purchase our software. The course data is kept as a back up in
the event the course needs us to replace their custom files. Each course has
a folder of it's own data under a centralized directory.

The problem:
The custom files are going to become a serious storage issue as our customer
base increases.

The solution:
Compress each course folder into an individual .cab file containing all of
the course's custom files and then archive these files to storage media such
as CD/DVD.

Where I need help:
I found some code for implementing a command line window and passing it a
string through a stream. The command window is being instantiated, but the
string is not getting passed or my syntax for running the makecab utility is
off-base. I've spent several hours looking for sample code that would
explain the makecab syntax and I've also tried to determine if the
parameters are being passed in to the Sub correctly. I've set a break at the
line where the string should be passed to the command window, but I can not
seem to get a respnse from the watches that have been set. I've included a
copy of the sub that I'm using to compress the files. If this is not the
correct forum for this, I do apologize. A nudge in the correct direction
would be deeply appreciated.

Private Sub CompressFolder( ByVal ToFolder As String, ByVal FromFolder As
String, ByVal FinalFile As String)

Dim CompressProcess As Process = New Process

CompressProcess .StartInfo.File Name = "cmd.exe"

CompressProcess .StartInfo.UseS hellExecute = False

CompressProcess .StartInfo.Crea teNoWindow = True

CompressProcess .StartInfo.Redi rectStandardInp ut = True

CompressProcess .StartInfo.Redi rectStandardOut put = True

CompressProcess .StartInfo.Redi rectStandardErr or = True

CompressProcess .Start()

Dim stmStreamIn As IO.StreamWriter = CompressProcess .StandardInput

stmStreamIn.Aut oFlush = True

Dim stmStreamOut As IO.StreamReader = CompressProcess .StandardOutput

Dim stmStreamErr As IO.StreamReader = CompressProcess .StandardError

stmStreamIn.Wri te("makecab.ex e /L %ToFolder% %FromFolder% %FinalFile%" &
System.Environm ent.NewLine)

stmStreamIn.Wri te("exit" & System.Environm ent.NewLine)

If Not CompressProcess .HasExited Then

CompressProcess .Kill()

End If

stmStreamIn.Clo se()

stmStreamOut.Cl ose()

stmStreamErr.Cl ose()

End Sub
Dec 9 '06
46 2537
Nothing massive. Each course folder may contain 1-2 subfolder's and a
maximum size of 20 MB. Nothing near the 2 GB limit. If I can't get the other
stuff with SharpZipLib to work, I may follow up on that one. Thanks for the
reply.

Bruce

"Stephany Young" <noone@localhos twrote in message
news:e1******** ******@TK2MSFTN GP06.phx.gbl...
>I haven't come across that one before but it is certainly one of the better
presented articles and projects at CodeProject.

Dec 11 '06 #11
Stephany,

Checked VB Defaults and Option Explicit was already on. Set Option Strict to
on and got two error's from my code, which I've resolved, with a little help
from a 'friend'. hehehehe I'll give this a shot and let you know what
happens. Thanks a boatload! from an old, senile wannabe! :)

Bruce

"Stephany Young" <noone@localhos twrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
You sure are having a bit of an issue!!!!!! :)

Before you even attempt to go any further, I stringly recommend that you
'turn' Option Strict and Option Explicit 'on' for ALL your VB.NET projects
and solutions. You can do this in Tools/Options. Expand the Projects and
Solutions node and select VB Defaults. Settings those to 'on' in there
will ensure that Option Strict and Option Explicit are automatically 'on'
for all new projects. For existing projects you will need to change the
settings for each individual project.

Option Explicit 'on' means that you must explicitly define each variable
before you can use it.

Option Strict 'on' means that the complier will make NO assumptions about
what the code should do. When you turn it on for this project than a
number of compile-time 'errors' will appear and you will need to correct
them all.

A number of the problems in the code fragment are caused by Option Strict
being 'off'. If you leave it turned off then you will continue to tear
your hair out because you not be able to spot various subtle problems.

Now for the nitty gritty.

Dim arystrmFolderNa mes() As String =
Directory.GetDi rectories(strSo urceDir)

This line create a string array that contains 1 element for each
sub-folder in whatever folder strSourceDir is pointing to. Each element
contains the name of (or the path to) a single sub-folder.

With the line (inside the loop):

Dim strmFile As FileStream = File.OpenRead(s trFolder)

you are attempting to open a sub-folder for reading and that is where you
are falling over. A folder (or directory) cannot be opened as if it were a
file. You need to walk the 'tree' and deal with each and every file in
each and every sub-folder.

Before we deal with that, the line:

Dim strTargetFile As String = strTargetDir &
arystrmFolderNa mes(intCounter) .LastIndexOfAny ("\")

must also be causing you problems. If your strTargetDir is "C:\Temp\" and
arystrmFolderNa mes(intCounter) is "C:\Data\Su bA" then strTargetFile will
become "C:\Temp\7" and I don't really think that is what you intend. I
suspect that you are looking for strTargetFile to be "C:\Temp\SubA.z ip".
If that is what you are looking for than you need to use something like:

Dim strTargetFile As String =
Path.ChangeExte nsion(Path.Comb ine(strTargetDi r,
Path.GetFileNam e(arystrmFolder Names(intCounte r))), "zip")

You use the phrase 'as the program trys to recurse through the subfolders
in FromFolder', but what your code is, in fact, doing is iterating through
the subfolders in FromFolder.

You do actually need to recursively walk the tree that starts at
FromFolder, dealing with every sub-folder including nested sub-folders and
handling every file that you encounter. This can be done with something
like:

Private Sub RecurseFolders( ByVal folder as String)

Dim _files as String() = Directory.GetFi les(folder)

For Each _file As String In _files
Dim strmFile As FileStream = File.OpenRead(_ file)
Dim abyBuffer(strmF ile.Length - 1) As Byte
strmFile.Read(a byBuffer, 0, abyBuffer.Lengt h)
strmFile.Close( )
Dim objZipEntry As New ZipEntry(_file)
objZipEntry.Dat eTime = DateTime.Now
objZipEntry.Siz e = abyBuffer.Lengt h
strmZipOutputSt ream.PutNextEnt ry(objZipEntry)
strmZipOutputSt ream.Write(abyB uffer, 0, abyBuffer.Lengt h)
Next

Dim _folders As String() = Directory.GetDi rectories(folde r)

For Each _folder in _folders
RecurseFolders( FromFolder)
Next

End Sub

Call this method for the appropriate place with:

RecurseFolders( FromFolder)

Let us know how you get on.
"Bruce W. Darby" <kr****@comcast .netwrote in message
news:FK******** *************** *******@comcast .com...
>>
"Rad [Visual C# MVP]" <no****@nospam. comwrote in message
news:rn******* ********@thinke rsroom.com...
>>If file size is paramount you might want to consider using better
compression formats (rar, bzip, etc). You can use sharpziplib to
accomplish
this sort of thing.

http://www.icsharpcode.net/OpenSourc...b/Default.aspx
--
Bits.Bytes
http://bytes.thinkersroom.com

Took a look into the sharpziplib you suggested and found it easier than
usual to add it to my solution, but I am having a bit of an issue. Not
sure what I'm doing wrong and hope that you can enlightem my fuzzy brain.
When I start the compression, I get an UnauthorizedAcc essException thrown
as the program trys to recurse through the subfolders in FromFolder. I
can understand that it's treating the subdirectories as files, but cannot
figure out why. Any tweaks or nudges? Code follows...

Private Sub CompressFolder( )

Dim strSourceDir As String = txtSelectDir.Te xt

If strSourceDir.Le ngth = 0 Then

MsgBox("Plea se specify a directory")

txtSelectDir.F ocus()

Exit Sub

Else

If Not Directory.Exist s(strSourceDir) Then

MsgBox("Direct ory not found")

txtSelectDir.F ocus()

Exit Sub

End If

End If

Dim strTargetDir As String = txtWriteDir.Tex t

If strTargetDir.Le ngth = 0 Then

MsgBox("Plea se specify a directory")

txtWriteDir.Fo cus()

Exit Sub

Else

If Not Directory.Exist s(strTargetDir) Then

MsgBox("Direct ory not found")

txtWriteDir.Fo cus()

Exit Sub

End If

End If

Dim arystrmFolderNa mes() As String =
Directory.GetD irectories(strS ourceDir)

Dim strmZipOutputSt ream As ZipOutputStream

Dim intCounter As Integer

Dim strTargetFile As String = strTargetDir &
arystrmFolderN ames(intCounter ).LastIndexOfAn y("\")

strmZipOutputS tream = New ZipOutputStream (File.Create(st rTargetFile))

strmZipOutputS tream.SetLevel( 9)

Dim strFolder As String

For Each strFolder In arystrmFolderNa mes

Dim strmFile As FileStream = File.OpenRead(s trFolder)

Dim abyBuffer(strmF ile.Length - 1) As Byte

strmFile.Read( abyBuffer, 0, abyBuffer.Lengt h)

Dim objZipEntry As ZipEntry = New ZipEntry(strFol der)

objZipEntry.Da teTime = DateTime.Now

objZipEntry.Si ze = strmFile.Length

strmFile.Close ()

strmZipOutputS tream.PutNextEn try(objZipEntry )

strmZipOutputS tream.Write(aby Buffer, 0, abyBuffer.Lengt h)

intCounter += 1

Next

strmZipOutputS tream.Finish()

strmZipOutputS tream.Close()

MsgBox("Operat ion completed")

End Sub

P.S. Please forgive my sloppy coding



Dec 11 '06 #12
Stephany,

THIS IS IT! :) I downloaded the .NET project from CodeProject last night and
messed around a bit with building the .dll before figuring out that it was
already built. LOL I then added it to the solution and started working with
the coding. Took me about 30 minutes to work it out with some of the code
that you so graciously provided in the SharZiplib examples. Fired up the
project and started stepping through the compression routine in my program
and it actually WORKED! Gee, guess I gotta think of myself as a bit more
than senile now, though I'll be danged if I can remember why... The cab file
is created in MS-Zip format, so it opened right up by double-clicking on the
..zip file. And it properly recursed all subdirectories. I'm almost finished
and am hoping that this will be the beginning of a fruitful learning
experience for me.

Again, thanks ever so much for the assistance.

Bruce

"Stephany Young" <noone@localhos twrote in message
news:e1******** ******@TK2MSFTN GP06.phx.gbl...
>I haven't come across that one before but it is certainly one of the better
presented articles and projects at CodeProject.

Dec 13 '06 #13
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.Te xt

Dim strTargetDir As String = txtWriteDir.Tex t

Dim _Folders As String() = Directory.GetDi rectories(strSo urceDir)

prbProgress.Min imum = 0

prbProgress.Max imum = CInt(_Folders.L ength)

prbProgress.Ste p = 1

For Each _Folder As String In _Folders

Dim strFldr2Compres s As String = Path.GetFileNam e(_Folder)

Dim strFinalFile As String = Path.ChangeExte nsion(Path.Comb ine(strTargetDi r,
_

Path.GetFileNam e(strFldr2Compr ess)), "cab")

Dim i_Compress As CabLib.Compress = New CabLib.Compress ()

i_Compress.Comp ressFolder(strT argetDir, strFinalFile, "", 0)

prbProgress.Per formStep()

lblProgress.Tex t = ("Compressin g: " & strFinalFile)

Next

End Sub

"Stephany Young" <noone@localhos twrote in message
news:e1******** ******@TK2MSFTN GP06.phx.gbl...
I can only suggest that you try it and see if it will work for you. If you
do then also test the extraction methods to ensure that you can actually
'restore' the data from the compressed file.

Dec 17 '06 #14
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" <kr****@comcast .netwrote in message
news:F-*************** *************** @comcast.com...
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.Te xt
Dim strTargetDir As String = txtWriteDir.Tex t
Dim _Folders As String() = Directory.GetDi rectories(strSo urceDir)
prbProgress.Min imum = 0
prbProgress.Max imum = CInt(_Folders.L ength)
prbProgress.Ste p = 1


Dec 17 '06 #15
Tom,

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

The procedure call would be something like...

CompressFolder( txtSelectDir.Te xt, txtWriteDir.Tex t)

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" <tl*****@nospam .netwrote in message
news:eP******** *****@TK2MSFTNG P04.phx.gbl...
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" <kr****@comcast .netwrote in message
news:F-*************** *************** @comcast.com...
>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.Te xt
Dim strTargetDir As String = txtWriteDir.Tex t
Dim _Folders As String() = Directory.GetDi rectories(strSo urceDir)
prbProgress.Mi nimum = 0
prbProgress.Ma ximum = CInt(_Folders.L ength)
prbProgress.St ep = 1



Dec 17 '06 #16
If I understand what you are trying to achieve correctly then you have a
folder structure that resembles;

C:\Top
Sub1
SubSub11
SubSub12
SubSub13
Sub2
SubSub21
SubSub22
SubSub23
Sub3
SubSub31
SubSub32
SubSub33

and what you want to end up with is a struncture that resembles:

C:\Compress
Sub1.cab
Sub2.cab
Sub3.cab

If that is the case then you logic is a bit flawed. The line
'i_Compress.Com pressFolder(str TargetDir, strFinalFile, "", 0)' should
probable read 'i_Compress.Com pressFolder(_Fo lder, strFinalFile, "", 0)'.

Apart from that, 7 out of 10 and here are your notes: :)

Dim strSourceDir As String = txtSelectDir.Te xt
Dim strTargetDir As String = txtWriteDir.Tex t

These 2 lines are completely redundant. Their values are seldom referred to
and never modified therefore the values can be used directly from the
TextBox controls. Before proceeding, I would be inclined to trim the content
of both TextBoxes to ensure that any leading and/or trailing whitespace,
that may be present, is removed. You may also like to add some validation to
ensure that values have been entered and the values entered are, in fact,
valid.

prbProgress.Min imum = 0

Unless you mave modified the value of prbProgress.Min imum elsewhere in your
app, (which is probalbly unlikely) then there is no need to set it here
because it is already 0. However, it is more likely that you have used the
ProgressBar elsewhere in you app so it is important to make sure that it
starts it's counting from 0 by resetting the value of prbProgress.Val ue.

prbProgress.Max imum = CInt(_Folders.L ength)

The Length property of an array returns an Integer so there is no need to
carry out any conversion when assigning it to any other object that is also
an Integer.

The Path.GetFileNam e(strFldr2Compr ess) in the 2nd line of the loop is, at
the least, redundant, but more importantly it is downright confusing. The
first line of the loop get the last node of the folder name and stores it in
a variable. To do carry out the operation again on the variable is
absolutely not necessary.

Now we can note that the only time that strFldr2Compres s is used is in the
very next line and therefore the use of an interim variable is not
necessary.

Dim i_Compress As CabLib.Compress = New CabLib.Compress ()

In VB.Net this can be shortened to 'Dim i_Compress As New CabLib.Compress '.
Also, the instantiation of i_Compress is being carried out on every
iteration of the loop, whereas it only needs to carried out once.

lblProgress.Tex t = ("Compressin g: " & strFinalFile)

At the point that this is executed the compression operation has already
finished so this line should appear earlier in the loop.

At the 2 points where UI elements are 'updated', the app is in a faily tight
loop and you may find that the ProgressBar and/or Label do not 'update' as
you might expect them to. A couple of forced updates will be of assistance
here to allow the UI Elements to repaint in a timely manner.

The modified method is shown below:

Private Sub CompressFolder( )

txtSelectDir.Te xt = txtSelectDir.Te xt.Trim()

txtWriteDir.Tex t = txtWriteDir.Tex t.Trim()

Dim _folders As String() = Directory.GetDi rectories(txtSe lectDir.Text)

prbProgress.Val ue = 0

prbProgress.Max imum = _folders.Length

prbProgress.Ste p = 1

Dim _compress As New CabLib.Compress

For Each _folder As String In _folders
Dim _finalfile As String =
Path.ChangeExte nsion(Path.Comb ine(txtWriteDir .Text,
Path.GetFileNam e(_folder)), "cab")
lblProgress.Tex t = ("Compressin g: " & _finalfile)
lblProgress.Upd ate()
_compress.Compr essFolder(_fold er, _finalfile, "", 0)
prbProgress.Per formStep()
prbProgress.Upd ate()
Next

End Sub

As you can see, it is now a bit leaner without the redundant variables and
with the loop having no extraneous logic in it.

Although I invariably use hugarian notation for names of controls as you
have done, (even if you didn't know you were doing it), I like to use
lowercase with a preceding underscore for naming all local variables. I find
that this gives me continual visual prompts as to the scope of objects.

Of course, all this is my opinion, and you should code in a style that suits
you.

Have fun dissect that lot :)
"Bruce W. Darby" <kr****@comcast .netwrote in message
news:F-*************** *************** @comcast.com...
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.Te xt

Dim strTargetDir As String = txtWriteDir.Tex t

Dim _Folders As String() = Directory.GetDi rectories(strSo urceDir)

prbProgress.Min imum = 0

prbProgress.Max imum = CInt(_Folders.L ength)

prbProgress.Ste p = 1

For Each _Folder As String In _Folders

Dim strFldr2Compres s As String = Path.GetFileNam e(_Folder)

Dim strFinalFile As String =
Path.ChangeExte nsion(Path.Comb ine(strTargetDi r, _

Path.GetFileNam e(strFldr2Compr ess)), "cab")

Dim i_Compress As CabLib.Compress = New CabLib.Compress ()

i_Compress.Comp ressFolder(strT argetDir, strFinalFile, "", 0)

prbProgress.Per formStep()

lblProgress.Tex t = ("Compressin g: " & strFinalFile)

Next

End Sub

"Stephany Young" <noone@localhos twrote in message
news:e1******** ******@TK2MSFTN GP06.phx.gbl...
>I can only suggest that you try it and see if it will work for you. If
you do then also test the extraction methods to ensure that you can
actually 'restore' the data from the compressed file.


Dec 17 '06 #17
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" <kr****@comcast .netwrote in message
news:O8******** *************** *******@comcast .com...
Tom,

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

The procedure call would be something like...

CompressFolder( txtSelectDir.Te xt, txtWriteDir.Tex t)

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" <tl*****@nospam .netwrote in message
news:eP******** *****@TK2MSFTNG P04.phx.gbl...
>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" <kr****@comcast .netwrote in message
news:F-*************** *************** @comcast.com...
>>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.Te xt
Dim strTargetDir As String = txtWriteDir.Tex t
Dim _Folders As String() = Directory.GetDi rectories(strSo urceDir)
prbProgress.M inimum = 0
prbProgress.M aximum = CInt(_Folders.L ength)
prbProgress.S tep = 1




Dec 17 '06 #18
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 "compressin g" 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@localhos twrote in message
news:e3******** ******@TK2MSFTN GP03.phx.gbl...
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" <kr****@comcast .netwrote in message
news:O8******** *************** *******@comcast .com...
>Tom,

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

The procedure call would be something like...

CompressFolder (txtSelectDir.T ext, txtWriteDir.Tex t)

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" <tl*****@nospam .netwrote in message
news:eP******* ******@TK2MSFTN GP04.phx.gbl...
>>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
strTargetDi r 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" <kr****@comcast .netwrote in message
news:F-*************** *************** @comcast.com...
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.Te xt
Dim strTargetDir As String = txtWriteDir.Tex t
Dim _Folders As String() = Directory.GetDi rectories(strSo urceDir)
prbProgress. Minimum = 0
prbProgress. Maximum = CInt(_Folders.L ength)
prbProgress. Step = 1



Dec 17 '06 #19
Stephany,

After posting last night, I ran back through my code and there was a LOT of
stuff that I discovered about my code being incomplete and illogical.*sigh *
I was pointing one directory too high AND was not using the correct source
to draw from. Took a bit for me to work it out, but found that I was using
the destination folder as my source folder and was getting some really weird
results. Tom's post last night and yours this morning really helped me get
things ironed out in my mind. Incorporating the parts that you posted this
morning, here is my new compression sub, hopefully all neat and tidy. I know
that this one works as it should. LOL I've also decided to use labels with
autoellilpsis turned on in place of the text boxes. I did this as a personal
attribute because of space issues and my own anal perspective toward
neatness. I am doing the sanity check on the label entries from a seperate
sub so that is taken care of. If the user doesn't select a From and To
folder, it won't go anwhere but back to the folderbrowserdi alog. Thanks
again for all the help.

The (hopefully) almost completed compression sub...

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

Dim _Folders As String() = Directory.GetDi rectories(strSo urceDir)

prbProgress.Max imum = _Folders.Length

prbProgress.Ste p = 1

prbProgress.Vis ible = True

lblProgress.Vis ible = True

For Each _Folder As String In _Folders

Dim strFinalFile As String = Path.ChangeExte nsion(Path.Comb ine(strTargetDi r,
_

Path.GetFileNam e(_Folder)), "cab")

lblProgress.Tex t = ("Compressin g: " & Path.GetFileNam e(_Folder))

lblProgress.Upd ate()

Dim i_Compress As New CabLib.Compress

i_Compress.Comp ressFolder(_Fol der, strFinalFile, "", 0)

prbProgress.Per formStep()

prbProgress.Upd ate()

Next

prbProgress.Vis ible = False

lblProgress.Vis ible = False

End Sub


Dec 17 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
6328
by: mike | last post by:
Hello, After trying to validate this page for a couple of days now I was wondering if someone might be able to help me out. Below is a list of snippets where I am having the errors. 1. Line 334, column 13: there is no attribute "SRC" <bgsound src="C:\My Documents\zingwent.mids"> You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is...
5
2196
by: John Flynn | last post by:
hi all i'm going to be quick i have an assignment due which i have no idea how to do. i work full time so i dont have the time to learn it and its due date has crept up on me .. As follows: Objectives The purpose of this assignment is to have you practice the design of object-oriented classes, including one or more of the following concepts
0
1840
by: xunling | last post by:
i have a question about answering ..... this topic is "need help" what do i have to write at te topic line, !after i have klicked the "answer message" button ive tried many possibilities, all dont work "Re:" need help "Re:need help"
9
2937
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
7
3306
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte buffer into the character pointer. The code looks like the following: #include <stdio.h> #include <stdlib.h> #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call,
15
4642
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to communicate with a MySQL database table on a web server, from inside of my company's Access-VBA application. I know VBA pretty well but have never before needed to do this HTTP/XML/MySQL type functions.
16
2539
by: pamelafluente | last post by:
I am still working with no success on that client/server problem. I need your help. I will submit simplified versions of my problem so we can see clearly what is going on. My model: A client uses IE to talk with a server. The user on the client (IE) sees an ASP net page containing a TextBox. He can write some text in this text box and push a submit button.
8
2750
by: skumar434 | last post by:
i need to store the data from a data base in to structure .............the problem is like this ....suppose there is a data base which stores the sequence no and item type etc ...but i need only the sequence nos and it should be such that i can access it through the structure .plz help me .
0
3961
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
20
4285
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site is structured as an upside-down tree, and (if I remember correctly) never more than 4 levels. The site basically grew (like the creeping black blob) ... all the pages were created in Notepad over the last
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10058
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7416
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6678
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.