Showing posts with label Visual C# 2010 Express. Show all posts
Showing posts with label Visual C# 2010 Express. Show all posts

Tuesday, February 21, 2017

Brief Comparison of Four Graphic Compilers

Brief Comparison of Four Graphic Compilers

In the last couple of months I've used four different compilers to create similar applications to interface with Windows to display and interact with forms and their widgets.

I first tried GtkAda.  I discovered that it was difficult to use and also seemed to be need work.  For instance, when I tried a text box it could be displayed but the user (that is, me) couldn't enter anything into it.

I next tried to use the Linux version of visual C# (Mono) using the Window operating system.  This requires the use of CygWin.  I attempted to use instructions from approximately seven years ago that I had saved and then newer ones that I found online.  With none of them could I completely finish the installation to enable me to use Mono to interface to Windows.  I was able to install the Mono that runs under Windows but runs as a DOS-like application in a Linux-like way.  But I couldn't get to the point where I could get Mono that runs as its own Windows application where I could determine if it could create Windows applications.  A number of years ago I did use Mono running under Linux where I could create visual applications.  But as much as I tried to follow the various online instructions of how to do an install for Windows, I wasn't able to succeed.

After giving up on that I went back to the Microsoft Visual Express compilers that I used years ago - Microsoft Visual C++ 2010 Express and Microsoft Visual C# 2010 Express.  My trial usage ran out years ago but I found I could still use them if I first launched the compiler and selected the application rather than trying to launch a particular previously created application.  (Note: Obtaining an updated compiler now costs thousands of dollars which is out-of-range for my recreational use.)

Since I had previously used C# for my exploratory projects, after discovering that I could still use the compilers by launching them, I tried creating Visual C++ application similar to the GtkAda application to see the difference.  That is, an application that displays a few buttons including those inside of a container and a text box and can interact with mouse clicks on these widgets.

The old Microsoft Visual C++ 2010 Express was much, much easier to use than GtkAda and, in addition, the text box could actually be used.  Although I couldn't find a way to know when the user was finished entering into the text box.  Online searches showed that others had the same problem and had devised ways such as using a timer to anticipate that the user was finished with their entry.

I added a Done button instead.   Then, read the entered text via the Done button event handler.  This resulted in finding out that the format of the text was not a C/C++ string but something else entirely that required a conversion to obtain a C/C++ string.

In looking into this I found comments such as "Microsoft's advise would seem to be if you want to do Windows Desktop UI code (with the .Net framework), use C# (or VB.NET)." rather than Visual C++ and, in response to a question, "Looks to me like you're using C++/CLI which is NOT C++. It is a completely different language created by Microsoft to supersede Managed Extensions for C++. (.NET)."

Therefore, I repeated the application in Visual C#.  The general code to create the widgets and the event handlers was much the same.  (Except for using dot notation in C# versus the '->' notation of the Visual C++.)  In each case, the code to initialize the widgets that were placed into the displayed form was created automatically.  Just in it own .cs file in C# versus being in the same file as the event handlers as in Visual C++.

In neither case was a Key Up or Down event handler added automatically when double clicking on the displayed widget.  Versus a handler for when the contents were changed which was.

But I was able to add a Key Down event handler to the C# application and manually add it to the initialization of the text box.  And without problem have it check if the key was the Enter (i.e., Return) key to indicate that the user was finished entering text.  Therefore, although I didn't remove the Done button from the form, it was no longer needed.

Also, the TextChanged event handler that was added by double clicking the text box wasn't needed for this application so it could have been eliminated.  Although it would be needed if trying to restrict the input of certain characters in some way – such as only to digits.

And when getting the entered text (upon detecting the use of the Enter key), a normal C string could be directly used.  Therefore, C# was much more C-like than Visual C++.

In conclusion, Visual C# was easier to use than Visual C++ and the entire application took less than a day.  So much different from GtkAda.  If memory serves at all, Mono under Linux was similar.

To complete this report, the code and the form (as first displayed before buttons or labels were hidden due to mouse clicks on other buttons or the entry of any text) are shown below.  Only the code inside an event handler had to be written along with the line to initialize the use of the KeyDown event handler for the text box.  The rest was generated by the compiler.

Note, button4_Click is the event handler for the Done button.  "Done" is the text displayed on the button via the button's properties.  The name of the button can be changed but I noticed, when I did so for Visual C++, the previously generated code wasn't always automatically updated.  So rather than needing to update the names my hand I didn't bother with the C# application since proper naming wasn't my concern in creating the application.  Thus I don't know if Visual C# would have tracked the property changes better.  And, of course, the compiler is many years out of date and a newer one would need to be used for an actual application.

Note:  In the display of the form, the container panel cannot be seen against the background of the form itself.  However, button3 is a child of the container.  If button1 is clicked button3 is hidden.  As can be seen from the code, the handler for button1 hides the panel as well as label1.  And hiding the panel of which button3 is a child, hides the button as well.


Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Form1.Designer.cs with Initialize
namespace WindowsFormsApplication1
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.panel1 = new System.Windows.Forms.Panel();
            this.button3 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button4 = new System.Windows.Forms.Button();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(447, 128);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // button2
            //
            this.button2.Location = new System.Drawing.Point(484, 259);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 1;
            this.button2.Text = "button2";
            this.button2.UseVisualStyleBackColor = true;
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(434, 223);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(46, 17);
            this.label1.TabIndex = 2;
            this.label1.Text = "label1";
            this.label1.Click += new System.EventHandler(this.label1_Click);
            //
            // panel1
            //
            this.panel1.Controls.Add(this.button3);
            this.panel1.Location = new System.Drawing.Point(114, 111);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(261, 190);
            this.panel1.TabIndex = 3;
            //
            // button3
            //
            this.button3.Location = new System.Drawing.Point(143, 81);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(75, 23);
            this.button3.TabIndex = 0;
            this.button3.Text = "button3";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(423, 377);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 22);
            this.textBox1.TabIndex = 4;
            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            this.textBox1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBox1_KeyDown);
            //
            // button4
            //
            this.button4.Location = new System.Drawing.Point(538, 376);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(52, 23);
            this.button4.TabIndex = 5;
            this.button4.Text = "Done";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(631, 462);
            this.Controls.Add(this.button4);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button button4;
    }
}

Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.label1.Visible == true)
            {
                this.label1.Visible = false;
                this.panel1.Visible = false;
            }
            else
            {
                this.label1.Visible = true;
                this.panel1.Visible = true;
            }

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (this.button2.Visible == true)
            {
                this.button2.Visible = false;
            }
            else
            {
                this.button2.Visible = true;
            }
        }

        private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
      if (this.label1.Visible == true)
{
   this.label1.Visible = false;
}
else
{
   this.label1.Visible = true;
}
if (e.KeyCode == Keys.Return)
{
   this.button1.Visible = false;
                 string standardString = textBox1.Text;
             }
}

        private void button4_Click(object sender, EventArgs e)
        {
             if (this.label1.Visible == true)
{
   this.label1.Visible = false;
}
else
{
   this.label1.Visible = true;
}
             string standardString = textBox1.Text;
        }    
    }
}


Monday, February 20, 2012

Using Visual C# 2010 Express to Check Multiple Folders for Duplicate Files Update


Using Visual C# 2010 Express to Check Multiple Folders for Duplicate Files Update

Since my previous post I have discovered an error such that not all the files of folders get compared.  So an update of the Form1.cs code is provided below.

Also, I have noticed a problem with my attempt to provide the user with a running status of the progress of the compares.  When I ran the application with the debugger the label control that displayed text as to the number of folders checked and the number of files checked and the label control that displayed the number of duplicates continuously updated as intended.  However, when the application was run via its .exe executable the labels would initially be updated.  But very shortly the wait cursor would be displayed without being requested and the updating would cease until all the compares had occurred when the cursor would return to the default and the totals would be displayed.

I have been unable to find a way to avoid this.  I've done internet searches and found various posts that purport to show how the programmer can prevent this from happening – that is, have updates of controls actually happen and be displayed.  None of those that I found have worked with my application.

I've also tried a progress bar which should surely work.  Again, it is continually updated if I run the application via the Visual C# 2010 Express debugger.  But, if the application is run via its executable, the wait cursor appears and the labels and progress bar cease being updated after the first 20 files or so.  So the progress bar no longer shows progress.

In addition I created a second project in which I used a worker thread to do the compares while the Form1 thread slept for 500 ms at a time and then did the updates in the Form1 thread before sleeping again.  No change in the update behavior.  That is, the label text didn't change and the progress bar didn't show any progress.

Any ideas anyone?

Form1.cs code

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
namespace Compare
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            // (Mostly) generated control initialization.
            InitializeComponent();

            // Add selections to the combo boxes.
            extensionComboBox.MaxDropDownItems = 4;
            extensionComboBox.Items.Add(extensions[0]);
            extensionComboBox.Items.Add(extensions[1]);
            extensionComboBox.Items.Add(extensions[2]);
            extensionComboBox.Items.Add(extensions[3]);

            existingReport.MaxDropDownItems = 2;
            existingReport.Items.Add(reportOptions[0]);
            existingReport.Items.Add(reportOptions[1]);

            // Create string from byte arrays to get new lines in the duplicates file.
            Byte[] cR = new Byte[] { 13 };
            Byte[] lF = new Byte[] { 10 };
            crNL = Encoding.ASCII.GetString(cR) + Encoding.ASCII.GetString(lF);
        }

        //----------------------------------------------------------------------
        // Compare files in the selected folders.
        private void CompareFiles()
        {
            // Display progress bar.
            progressBar.Minimum = 1;
            progressBar.Maximum = 0;
            for (int f = 0; f < folderCount; f++)
            {
                progressBar.Maximum = progressBar.Maximum + 
                                      folderFile[f].list.Count();
            }
            progressBar.Value = 1;
            progressBar.Step = 1;
            progressBar.Visible = true;
            progressBar.Update();

            // Display Please Wait.
            pleaseWait.Visible = true;
            pleaseWait.Refresh();

            // Compare files of all folders starting with first file of first folder
            // to compare with the other files of that folder and then those of the
            // other folders.  Then proceed to the next file of the first folder and
            // repeat.  Then to the first file of the next folder to check the files
            // of that folder and the remaining folders.  And repeat.
            for (int f = 0; f < folderCount; f++) // Check folders for those not yet
            {                                                       //  completely compared
                // Select initial default folder and list.
                int defaultFolder = f;
                IEnumerable<System.IO.FileInfo> defaultList =
                                                folderFile[defaultFolder].list;

                FileInfo lastIndex = defaultList.Last();
                // Ignore list if no files with selected extension.
                if (defaultList.Count() > 0)
                {
                    string defaultFileName = defaultList.First().FullName;
                    FileStream defaultFileStream = null;

                    defaultIndex = 0;
                    defaultCount = 0;
                    if (defaultFiles == null)
                    {
                        defaultFiles = new string[defaultList.Count()];
                    }
                    else if (defaultFiles.Count() < defaultList.Count())
                    {
                        defaultFiles = new string[defaultList.Count()];
                    } // else reuse the defaultFiles array
                    foreach (var v in defaultList)
                    {
                        defaultFiles[defaultCount] = v.FullName;
                        defaultCount++;
                    }

                    // Compare particular file in the list to the other files of the list
                    // and the other lists (if not already in the duplicate table).
                    for (defaultIndex = 0; defaultIndex < defaultCount; defaultIndex++)
                    {
                       // Select the file.
                       defaultFileName = defaultFiles[defaultIndex];
                        // Ignore file if already found as a duplicate.
                        if (!InDuplicateTable(defaultFileName))
                        { 
                            // Open the selected file for Read-Only.
                            try
                            {
                                defaultFileStream = new FileStream(defaultFileName,
                                                                   FileMode.Open,
                                                                   FileAccess.Read);
                                if (defaultFileStream != null)
                                {   // Find any duplicates of the selected file.
                                    CompareSelectedFile(defaultFolder, defaultFileName,
                                                        defaultFileStream );
                                    // Close the selected file.
                                    defaultFileStream.Close();

                                    // Attempt to continue update without showing the
                                    // wait cursor when running exe.
                                    comparedCount++;
                                    CompareStatus.Text = "Folder " + (f + 1) + "  " +
                                                         comparedCount + " files compared";
                                    CompareStatus.Visible = true;
                                    CompareStatus.Refresh();
                                    numberDuplicates.Text = "Number of duplicate files is "
                                                            + duplicatesReported;
                                    numberDuplicates.Visible = true;
                                    numberDuplicates.Refresh();
                                    progressBar.Value = comparedCount;
                                    progressBar.PerformStep();
                                    progressBar.Update();
                                } // end if
                            } // end try
                            catch (Exception ex)
                            {
                                MessageBox.Show("Error: Unable to open first file " +
                                                defaultFileName +
                                                " " + ex.Message);
                            }
                        } // end if (!InDuplicateTable(defaultFileName))
                      
                    } // end loop for each file in current list

                } // end if (defaultList.Count() > 0)

                // Indicate that the folder has been searched.
                folderFile[f].searched = true;

            } // end loop thru selected folders

            // Hide Please Wait and progress bar.
            pleaseWait.Visible = false;
            progressBar.Visible = false;

            // Output count of duplicate files.
            Byte[] text = new UTF8Encoding(true).GetBytes("Number of duplicate files is "
                + duplicatesReported + crNL);
            duplicatesReport.Write(text, 0, text.Length);
            duplicatesReport.Flush();

            // Display Done OK button to allow user to see number of duplicate files.
            // When clicked, the application will be terminated.
            doneButton.Visible = true;

        } // end method CompareFiles

        //----------------------------------------------------------------------
        // Compare particular file in the list to the other files of the
        // selected folder list and the other lists that follow it.
        // Notes: All files in a list previous to the selected folder have
        //        already been compared.
        private void CompareSelectedFile(int selectedFolder, string selectedFileName,
                                         FileStream fs1)
        {
            for (int f = selectedFolder; f < folderCount; f++)
            {   // Check folders for those not yet completely compared
                if (f == selectedFolder)
                {   // Compare from next file forward thru the selected folder
                    for (int index = defaultIndex+1; index < defaultCount; index++)
                    {
                        FileCompare(fs1, defaultFiles[index]);
                    }
                }
                else
                {   // Compare all the files of the folder
                    foreach (var v in folderFile[f].list)
                    {
                       FileCompare(fs1, v.FullName);
                    }
                }
            }  // end loop over folders

         } // end method CompareSelectedFile

        //----------------------------------------------------------------------
        // This method accepts two strings the represent two files to
        // compare. A return value of 0 indicates that the contents of the files
        // are the same. A return value of any other value indicates that the
        // files are not the same.
        // Notes: This method is somewhat modified from a Microsoft example.
        private void FileCompare(FileStream fs1, string file2)
        {
            int file1byte;
            int file2byte;

            FileStream fs2 = null;

            // Open the second file.
            try
            {
                fs2 = new FileStream(file2, FileMode.Open, FileAccess.Read);
            }
            catch (Exception ex)
            {
                if (ex.Message.StartsWith("Access to the path") &&
                     fileError.StartsWith("Access to the path"))
                { // bypass the reporting of the exception
                }
                else
                { // display the first instance of the exception
                    fileError = ex.Message;
                    MessageBox.Show("Error: Unable to open second file " + file2 + " "
                        + ex.Message + " Further such errors will be ignored.");
                }
            }

            // If can't open the file, return since can't compare the files.
            if (fs2 == null)
            {
                MessageBox.Show("ERROR: Couldn't open " + file2);
                return;
            }

            // Check the file sizes. If they are not the same, the files
            // are not the same.
            if (fs1.Length != fs2.Length)
            {
                // Close the file and return since no need to compare the files
                fs2.Close();
                return;
            }

            // Read and compare a byte from each file until either a
            // non-matching set of bytes is found or until all the bytes
            // have been compared.
            int bytesRead = 0;
            do
            {
                // Read one byte from each file.
                file1byte = fs1.ReadByte();
                file2byte = fs2.ReadByte();
                bytesRead++;
            }
            while ((file1byte == file2byte) && (bytesRead <= fs1.Length)) ;

            // Close the file.
            fs2.Close();

            // If the last bytes read are equal, the files are the same.  Add the
            // duplicate file pair to the duplicate array and duplicates report.
            if ((file1byte - file2byte) == 0 )
            {   // add file pair to duplicate array
                if (duplicateCount < maxDuplicates)
                {
                    duplicateFiles[duplicateCount] =
                        new DuplicateFile(fs1.Name, file2);
                    duplicateCount++;
                }
                else if (!maxDuplicatesDisplayed)
                {
                    maxDuplicatesDisplayed = true;
                    MessageBox.Show("ERROR: Maximum number of duplicates of "
                                     + maxDuplicates + " exceeded");
                }

                // Add file pair to duplicates report
                duplicatesReported++;
                Byte[] text = new UTF8Encoding(true).GetBytes(fs1.Name
                                   + " " + file2 + crNL);
                duplicatesReport.Write(text, 0, text.Length);
                duplicatesReport.Flush();
            } // end if

        } // end function FileCompare

        //----------------------------------------------------------------------
        // Return true if file is in the duplicate table. 
        // Note: The name1 column is for the default file for which duplicates
        //       have been found.  The file passed is for a newly chosen file
        //       so could only be a file in the name2 column.
        private bool InDuplicateTable(string file)
        {
            for (int i = 0; i < duplicateCount; i++)
            {
                if (file.Equals(duplicateFiles[i].name2))
                {
                    return true;
                }
            }

            return false;

        } // end function InDuplicateTable

        //----------------------------------------------------------------------
        // Obtain folder names and display in list box and open report file.
        private void ObtainFolderNames(string ext) // ext is selected file extension
        {
            string folder = "";
            bool selectFolder = true;
            System.IO.DirectoryInfo[] dir = new DirectoryInfo[maxFolders];

            // Do not allow the user to create new files via the FolderBrowserDialog.
            folderBrowserDialog1.ShowNewFolderButton = false;

            // Obtain folders to be searched for duplicate files with the
            // selected extension.
            while (selectFolder && folderCount < dir.Length)
            {
                if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
                {
                    folder = folderBrowserDialog1.SelectedPath;

                    // Check that folder not already selected.
                    bool newFolder = true;
                    for (int f = 0; f < folderCount; f++)
                    {
                        if (folder.Equals(folderFile[f].name))
                        {
                            newFolder = false;
                            break;
                        }
                    }

                    if (newFolder)
                    {
                        folderListBox.Items.Add(folder);
                        folderListBox.Refresh();
                        dir[folderCount] = new System.IO.DirectoryInfo(folder);

                        IEnumerable<System.IO.FileInfo> folderList =
                            dir[folderCount].GetFiles(
                               ext, System.IO.SearchOption.AllDirectories);
                        folderFile[folderCount] = new FolderFile(folder, folderList);
                        folderCount++;
                    } // end if (newFolder)
                }
                else
                {
                    selectFolder = false;
                }
            } // end select folders loop
            folderListBox.Refresh();

            // Quit if nothing selected.
            if (folderCount == 0)
            {
                Console.WriteLine("ERROR: no folders selected");
                this.Close(); // close form
                return;
            }

            // Open disk file to report duplicates.  Check if already available
            // and, if so, ask if to overwrite or add new entries at the end. 
            // If not available, create the file.
            duplicatesReportFileName = folderFile[0].name + "\\DuplicateFiles.txt";
            try
            {
                duplicatesReport = File.Open(duplicatesReportFileName,
                                             FileMode.Open, FileAccess.Read);
                long size = duplicatesReport.Length;
                if (size > 0)
                {
                    duplicatesReport.Close();
                    existingReport.Visible = true;
                    existingReport.Refresh();
                    return; // allow append or overwrite to be selected
                }
                else
                {
                    duplicatesReport.Close();
                    duplicatesReport = File.Open(duplicatesReportFileName,
                                                 FileMode.Append, FileAccess.Write);
                }
            }
            catch //(Exception ex)
            {
                duplicatesReport = File.Open(duplicatesReportFileName,
                                             FileMode.CreateNew, FileAccess.Write);
            }

            // Compare the selected files.
            CompareFiles();

        } // end method ObtainFolderNames

        //----------------------------------------------------------------------
        // Event handlers

        // Hide OK button and then select the folders of the files to be
        // compared and do the compare.
        private void buttonOK_Click(object sender, EventArgs e)
        {
            buttonOK.Visible = false;
            ObtainFolderNames(extension);

        } // end event handler buttonOK_Click

        //----------------------------------------------------------------------
        // Allow operator to terminate
        private void doneButton_Click(object sender, EventArgs e)
        {
            doneButton.Visible = false;
            this.Close(); // close form
            return; // finished running
        } // end event handler doneButton_Click

        //----------------------------------------------------------------------
        // Input file extension to be used and be sure of leading "*." and
        // wait until validated.
        public void extensionTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            extension = extensionTextBox.Text; // input latest text
            if (e.KeyCode == Keys.Enter)       // all chars entered
            {   // edit entered extension
                char[] chars  = new char[extension.Length];
                chars = extension.ToCharArray();
                if (chars[0].Equals('*') && chars[1].Equals('.'))
                { // both leading characters in string
                }
                else if (!chars[0].Equals('.'))
                { // no leading '.' so add it
                    extension = "." + extension;
                    if (!chars[0].Equals('*'))
                    { //--->>> this not going to work???
                        extension = "*" + extension;
                    }
                }
                else
                { // leading '.' so add leading '*'
                    extension = "*" + extension;
                }

                extensionTextBox.Text = extension; // display what will be used
                buttonOK.Visible = true; // to allow validation of the extension wanted
            } // end if (e.KeyCode == Keys.Enter)

        } // end event handler extensionTextBox_KeyDown

        //----------------------------------------------------------------------
        private void folderListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
        } // end event handler folderListBox_SelectedIndexChanged

        private void CompareStatus_Click(object sender, EventArgs e)
        {
        } // end event handler CompareStatus_Click

        //----------------------------------------------------------------------
        // Obtain the selected extension and display and wait until validated.
        private void extensionComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = extensionComboBox.SelectedIndex;
            extension = extensions[index];
            extensionTextBox.Text = extension; // display what will be used
            buttonOK.Visible = true; // to allow validation of the extension wanted
        } // end event handler extensionComboBox_SelectedIndexChanged

        //----------------------------------------------------------------------
        // Obtain the selected option and open append or open create as requested.
        private void existingReport_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = existingReport.SelectedIndex;
            if (index == 0) // Append
            {
                duplicatesReport = File.Open(duplicatesReportFileName, FileMode.Append,
                                             FileAccess.Write);
            }
            else
            {
                duplicatesReport = File.Open(duplicatesReportFileName, FileMode.Create,
                                             FileAccess.Write);
            }
            existingReport.Visible = false;

            // Compare the selected files.
            CompareFiles();

        } // end event handler existingReport_SelectedIndexChanged

        //----------------------------------------------------------------------
        // Class variables

        // File extension to use for files to be compared
        string extension = "";
        string[] extensions = new string[] { "*.jpg", "*.bmp", "*.doc", "*.txt" };

        string[] reportOptions = new string[] { "Append", "Overwrite" };

        const int maxFolders = 15;
        const int maxDuplicates = 300;
        string crNL = null;

        string fileError = "";

        public struct FolderFile
        {
            public IEnumerable<System.IO.FileInfo> list; // list of file names
            public string name;            // folder name
            public bool searched;          // whether folder has been searched
   
            public FolderFile(string name, IEnumerable<System.IO.FileInfo> list)
            {   // add new folder name and its file list to the structure
                this.name = name;
                this.list = list;
                this.searched = false;
            } // end constructor
        }

        // Files of the currently selected folder
        private int defaultIndex = -1;
        private int defaultCount = 0;
        private string[] defaultFiles = null; //string[];
        public struct DuplicateFile
        {
            private string name1;
            public string name2;
            public DuplicateFile(string name1, string name2)
            {   // add new pair of duplicated files to the structure
                this.name1 = name1;
                this.name2 = name2;
            }
        }

        // Number of selected folders and array of selected folders
        private int folderCount = 0;
        private FolderFile[] folderFile = new FolderFile[maxFolders];

        // Number of compared file pairs
        private int comparedCount = 0;

        // Number of duplicate file pairs and array containing them
        private bool maxDuplicatesDisplayed = false;
        public int duplicateCount = 0;
        public DuplicateFile[] duplicateFiles = new DuplicateFile[maxDuplicates];
       
        // Disk file text writer of the duplicate file pairs to examine when finished
        private int duplicatesReported = 0;
        private string duplicatesReportFileName = "";
        static private FileStream duplicatesReport = null;

    } // end class Form1

} // end namespace Compare