string contentsOfSelection; //the current contents of the selected cell before any changes are made.

        /// <summary>
        /// Constructor for GUI. Also instantiates a new Spreadsheet.
        /// </summary>
        public SpreadsheetGUI()
        {
            InitializeComponent();
            spreadsheet         = new Spreadsheet(IsValidVariable, ToUpperCase, "ps6");
            fileName            = "";
            editStack           = new UndoRedoStack();
            contentsOfSelection = "";
        }
        /// <summary>
        /// Checks if any changes have been saved. Prompts user to save them if not. Opens the open dialog box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenButton_Click(object sender, EventArgs e)
        {
            //Unsaved Changes
            if (spreadsheet.Changed)
            {
                DialogResult saveChanges = SaveChangesBeforeClosingFile();
                if (saveChanges == DialogResult.Yes)
                {
                    if (fileName == "")
                    {
                        ShowSaveDialog();
                    }
                    else
                    {
                        spreadsheet.Save(fileName);
                    }
                }
                else if (saveChanges == DialogResult.No)
                {
                    // Do nothing and skip to the code below
                }
                else //If user selects "Cancel"
                {
                    return; //Skip the code below
                }
            }

            //The logic comes here if the user chose "Yes" or "No"

            //Open File Dialog
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.DefaultExt = "sprd";
            openFile.Filter     = "sprd files (*.sprd)|*.sprd|All files (*.*)|*.*";
            if (openFile.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    ClearAllCells();
                    spreadsheet = new Spreadsheet(openFile.FileName, s => true, ToUpperCase, "ps6");
                }
                catch (Exception exception)
                //if there is a problem opening the file, tell the user and just open an empty spreadsheet.
                {
                    MessageBox.Show("There was a problem opening the file:\n" + exception.Message, "", MessageBoxButtons.OK);
                    spreadsheet = new Spreadsheet();
                }
                fileName  = openFile.FileName;
                editStack = new UndoRedoStack();
                UpdateCells(spreadsheet.GetNamesOfAllNonemptyCells());
            }
        }