Folder or File?

Hi,
I am not a total newbie, but but by no means an expert.

I have a little app.
It processes a file or a batch of selected files.

I am trying to enhance it to make it a little more user friendly.

Right now, using FileOpenDialog user can choose a file or multiple files to process.
This works, no problem, but have some "user interface" issues:

1. File or Folder?
If user just wants to process one file, then ok, no issue.
If user wants to process a batch of files, then user has to navigate to the folder, open the folder, then choose the first file and then scroll down and shift-select the last file.

I am trying to save the user some clicking & scrolling, etc.
If they want to process all the files in a folder, I would like give them the option of selecting the folder (as opposed to opening the folder and selecting the files)

Funcitonally no different - just to me would save the user some clicking/scrolling etc.

Is there a way to change the parameters on the FileOpenDialog to allow user to choose folder or file/files?

I can use the FolderBrowseDialog method, but then if they just want one file, have to give/present both methods, which would be confusing.
Is there a way to combine the interface?

2.
Put this under screen redraw, and providing feedback to user.
And a little more important.

Right now, to simplify the code, I have:
cOpenFileDialog
For each FileName in cOpenFile.FileNames
- do the processing
Next
cOpenFile.Dispose

This causes 2 issues:
because the cFileOpen is not closed until after processing is finished
a. the screen does not look right. It has part of the Form1 showing (with buttons, etc.) overlayed with a remnant of the file open dialog box.
Once it is done processing then it finishes redrawing the Form1 (I hope this makes sense - you can understand what I mean)

b. from a functionality point of view.
Rather than user choosing files, then off it goes, I would like to provdie feedback first.
Such as a TextBox that says:
-if one file chosen "You have chosen filename.ext"
- if multiple chosen "You have chosen 43 files in FolderName"

Then if the user, is happy they can then click on a "OK Process" button or such.

But because of the cOpenFileDialog->Process->cOpenFile Close, sequence, no chance to do that.

But if I do this: cOpenFile->Close Dialog->Give Feedback->Process, the app has lost track of what files to process.

Any ideas?
Thanks.
[2633 byte] By [tlfeet] at [2007-11-18 17:34:41]
# 1 Re: Folder or File?
I'm assuming this is related to the last project I made for you, so here it is with some modification. The rest is up to you ;)
Craig Gemmill at 2007-11-10 3:21:58 >
# 2 Re: Folder or File?
Hi Craig,
Yes it is me.
Yes it is getpixel. :D

I should just turn this over to you. :D

I terms of adding to it to do the number crunching on the pixels that I need to do making quite a bit of progress.

[One "lttle" problem on that end]

I thought about doing a listbox or an array to store the filenames, and this will work, but I was wondering:
"What is the limit to the number of items?"

Right now, in writing, testing, debugging, working on one file at a time, or at most a handful, but when we really start using this, we would be doing thousands of files at a time.
-Most likely, install it on a box, come in in the morning, select a bunch and let it crunch all day, into the next...

The limit issue has hit me on the number crunching end.
jpegs or ok, in that they have 3 values R,G,B and given our jpegs, I can ignore the Alpha channel.

I store the frequncy count in a 3-dimension array:
Dim FrequencyCount(255,255,255) As Integer

If I wish to extend functionality to handle other formats, then need:
Dim FrequencyCount(255,255,255,255) As Integer
and boom get out of memory error, crash.

But MS documentation (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconDeclaringArrays.asp) says this:

The total size limit of an array varies, based on your operating system and how much memory is available. Using an array that exceeds the amount of RAM available on your system is slower because the data must be read from and written to disk.

So, why is it not reading/writing to disk?
Yes, that would slow it down, bummer, but get a crash, which is worse.
I suppose somewhere I have to tell it to read/write the array to disk?

Thanks Craig.
You are a lifesaver.
Now I owe you 2 dinners!
tlfeet at 2007-11-10 3:22:58 >
# 3 Re: Folder or File?
[EDIT]
Ok I just did some testing, and it appears that multidimensional arrays grow exponentially (<-maybe not the right word).

myArray(9).Length = 10
myArray(9, 9).Length = 100
myArray(9, 9, 9).Length = 1000

myArray(255,255,255,255).Length = 4228250625

You can do it this way instead:

Dim myRedValues(254)
Dim myGreenValues(254)
Dim myBlueValues(254)

Or CMYK, etc...
Craig Gemmill at 2007-11-10 3:23:50 >
# 4 Re: Folder or File?
Hi Craig,

I have a little "beta" version of my little app.
Available here:
http://www.blueorbwise.net/project1/whatisblue/index.html

Thank you very much for the help.
tlfeet at 2007-11-10 3:24:55 >
# 5 Re: Folder or File?
Cool idea. I have a couple suggestions after briefly reviewing the code:

1) For speed sake, take a look at the Bitmap.Lockbits method instead of using GetPixel(x,y). http://www.bobpowell.net/lockingbits.htm

2) If you continue to use GetPixel, do not keep calling it on the same pixel. Call it once and store that value in a variable.

Dim cMyColor as Color

cMyColor = bitmap.GetPixel(10,10)

cMyColor.whatever
cMyColor.whatever
cMyColor.whatever
cMyColor.whatever

3) Be aware that there are two division operators in VB.NET. \ and /. Use \ when you don't need the remainder, as it can be MUCH faster.

Thanks for the follow up too.
Craig Gemmill at 2007-11-10 3:25:53 >
# 6 Re: Folder or File?
Hi Craig,

Thanks for the tips.
Before I get to them, I have a question.

As you might have noticed, I give you credit for helping out on the webapge.

I also intend to put a blurb in code, thanking you and others.
So on the webpage and/or in the code (mayne eventually an About page or Credits page) would like to include and bio info and/or contact info?
Such as you email address, or such?
Brief programming bio?

Let me know.

Now on to your tips:

1) I read the link you provided.
A little over my head at this point, so I must do some more reading on it.
Of course, it does mean a bit more coding too.
Gee, I don't know I might even look at the help files. :)

2) Actually, originally I read the pixels into an array and then worked with the array.
But, it actually is not any faster, I believe, especially because of the averaging:
Method A:
Read in all pixels into array, then go back thru the array to do the averaging - is that not slower?

Method B: Say averaging over a 3x3 area. Cannot calcualte for the first pixel, let us say, until row 2 column 2 read into the array, at which point then could go back thru that part of the array to average over/for the first pixel - so in essence still going thru things twice - plus have to add in a lot of code to keep track of what pixel it is currenlty on, and where in the array in can start/stop averaging.

By dropping use of array, code was greatly simplified and did not notice drop in speed.

I would be first one to admit, that just because I did not notice drop in speed, it does not mean speed did not in fact drop.

But that is some of the testing I am doing.
And I was even going to post and ask about it, too, but never got a roundtoit - keep running out of roundtoits :)

3) The divisoin symbols.
Hopefully I did not use "\" inadvertently where I did not wish to cut off the remainder.
[And everyone knows I never make a typing mstake]

I was unaware of "\" and as you probably noticed there are quite a few places where I do not wish to have the remiander. I was using CInt and such, in those places.

Thanks again.
tlfeet at 2007-11-10 3:27:03 >
# 7 Re: Folder or File?
If i would need my user to be able to select or all files in a folder or a multiselect, I'd do the following.
Use the FolderBrowseDialog to let the user select a folder.
Upon selecting a folder, fill a listbox with all the fillnames in the folder... Add a button next to your listbox which does a select all.
Put a button at the other side of the listbox to start processing, and use msgbox to confirm.
Unfortunately I don't use this with files in subfolders of the selected folder...

Hope this helps...
PegasuZ at 2007-11-10 3:28:03 >