Author Topic: progress bar woes  (Read 2510 times)

0 Members and 1 Guest are viewing this topic.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
progress bar woes
« on: April 13, 2010, 06:06:47 PM »
OK, I must be losing my mind.  Using code from Kerry's post on file recursion, I am trying to make a progess bar to let the user know it didn't hang up.  My folder I'm starting with has 31 drawings in it.  The code runs, and then crashes when the count goes to 32...
Code: [Select]
       private void btnFindDups_Click(object sender, EventArgs e)
        {
            
            string pathCFiles = txtCompletedFiles.Text;
            string[] arrCompletedDrawings = Directory.GetFiles(pathCFiles, "*.dwg");
            string dupeFile = pathCFiles + "\\" + "Dupes.txt";
            string pathLockedFiles = txtSearchFolder.Text;
            progressBar1.Visible = true;
            progressBar1.Minimum = 1;
            progressBar1.Maximum = arrCompletedDrawings.Count();
            progressBar1.Value = 1;
            foreach (string dwg in arrCompletedDrawings)
            {
                string filedwg = dwg.Substring(dwg.LastIndexOf("\\") + 1);
                LoadDirFiles(pathLockedFiles, true, filedwg, dupeFile);
                progressBar1.Value += 1;
                
            }
            MessageBox.Show("Completed Search for Duplicates");
        }
and the search code
Code: [Select]
static void WriteDups(string dupDWG, string dupFile)
        {
            StreamWriter sw = new StreamWriter(dupFile, true);
            sw.WriteLine(dupDWG);
            sw.Close();
        }
private void LoadDirFiles(string Dir, bool CheckSubs, string dwgTF, string dupFile)
        {
            string[] fls = Directory.GetFiles(Dir);

            foreach (string fl in fls)
            {
                string filedwg = fl.Substring(fl.LastIndexOf("\\") + 1);
              
                if (dwgTF == filedwg)
                {
                    WriteDups(fl, dupFile);
                    
                }
            }
            if (CheckSubs)
            {
                string[] dirs = Directory.GetDirectories(Dir);
                foreach (string d in dirs)
                {
                    LoadDirFiles(d, CheckSubs, dwgTF, dupFile);
                }
            }
        }
« Last Edit: April 13, 2010, 06:55:50 PM by CmdrDuh »
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: progress bar woes
« Reply #1 on: April 13, 2010, 06:17:48 PM »
Just looking at the code.  You say the max is 31, and the min is 1.  Once you finish the first drawing, you progress meter is set to 2.  So when you finish all the drawings, you meter is set to 32 ( more than your max ).  Either start at 0, or add one to the max count.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: progress bar woes
« Reply #2 on: April 13, 2010, 06:25:33 PM »
See, I told you I was losing my mind.  Thanks Tim, I knew it was something easy
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: progress bar woes
« Reply #3 on: April 13, 2010, 06:29:58 PM »
Hi David,
were you referring to this one ? http://www.theswamp.org/index.php?topic=29992.msg355647#msg355647

I should start keeping better notes on my research 'cause my memory is not what it used to be  :(

I think Tim is correct

Just for fun, what happens if you try this

progressBar1.Maximum = (5 + arrCompletedDrawings.Count() );

edit: [oops] late to the party again [/oops]
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: progress bar woes
« Reply #4 on: April 13, 2010, 06:47:42 PM »
Nope, this one
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: progress bar woes
« Reply #5 on: April 13, 2010, 06:48:49 PM »
Kerry, I had to study yours and TT's code for 2 days to figure out what TT was saying.  I still don't understand why he said your was not recursive
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Tuoni

  • Gator
  • Posts: 3032
  • I do stuff, and things!
Re: progress bar woes
« Reply #6 on: April 14, 2010, 05:12:08 PM »
I still don't understand why he said your was not recursive
Because a recursive method is one which calls itself on its results.  Kerry's is basically working its way through a stack until there's nothing left to push/pop.

But both of them hurt my head :lol: