Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

Sum All Values

Description
Takes a list of values separated by line endings and sums all the values if it can. A message box will be shown with the summed value. If not all values are numeric, you will receive an additional warning, but the numeric values will still be summed. The summed value is then placed in the clipboard.
Language
C#.net
Minimum Version
Created By
wooster11
Contributors
-
Date Created
Aug 19, 2014
Date Last Modified
Aug 19, 2014

Macro Code

using System;
using System.IO;
using System.Windows.Forms;

public static class ClipboardFusionHelper
{
    public static string ProcessText(string text)
    {
        StringReader sr = new StringReader(text);
      bool notAllValuesAreNumeric = false;
      double summedValues = 0.0;
      string lineStringVal;
      lineStringVal= sr.ReadLine();
      while (lineStringVal != null)
      {
          double val;
          if (Double.TryParse(lineStringVal, out val))
             summedValues += val;
            else
                notAllValuesAreNumeric = true;
            
            lineStringVal = sr.ReadLine();
        }

        string message = "Sum: " + summedValues.ToString();
        if (notAllValuesAreNumeric)
          message += "\n!!!NOTE: Not All Values were numeric.!!!";

      MessageBox.Show(message, "Sum of All Lines", MessageBoxButtons.OK, MessageBoxIcon.Information);
        return summedValues.ToString();
    }
}