/// <summary> /// Multiplies the values in a field (column) of records in a list /// or database that match conditions that you specify. /// </summary> /// <param name="args"><para> /// The args contains 3 items: database, field, criteria. /// </para> /// <para> /// Database is the range of cells that makes up the list or database. /// A database is a list of related data in which rows of related /// information are records, and columns of data are fields. /// The first row of the list contains labels for each column. /// </para> /// <para> /// Field indicates which column is used in the function. /// Enter the column label enclosed between double quotation marks, /// such as "Age" or "Yield," or a number (without quotation marks) /// that represents the position of the column within the list: /// 1 for the first column, 2 for the second column, and so on. /// </para> /// <para> /// Criteria is the range of cells that contains the conditions you /// specify. You can use any range for the criteria argument, /// as long as it includes at least one column label and at least /// one cell below the column label in which you specify a condition for the column. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); if (((args[0] == null) || (args[1] == null)) || (args[2] == null)) { throw new ArgumentNullException(); } CalcArray database = CalcConvert.ToArray(args[0]); object field = args[1]; CalcArray criteria = CalcConvert.ToArray(args[2]); double num = 1.0; IEnumerator enumerator = new DatabaseEnumerator(database, field, criteria); while (enumerator.MoveNext()) { object current = enumerator.Current; if (CalcConvert.IsNumber(current)) { double num2; if (!CalcConvert.TryToDouble(current, out num2, true)) { return(CalcErrors.Value); } num *= num2; } else if (current is CalcError) { return(current); } } return(CalcConvert.ToResult(num)); }
/// <summary> /// Counts the cells that contain numbers in a field (column) of /// records in a list or database that match conditions that you specify. /// </summary> /// <param name="args"><para> /// The args contains 3 items: database, field, criteria. /// </para> /// <para> /// Database is the range of cells that makes up the list or database. /// A database is a list of related data in which rows of related /// information are records, and columns of data are fields. /// The first row of the list contains labels for each column. /// </para> /// <para> /// Field indicates which column is used in the function. /// Enter the column label enclosed between double quotation marks, /// such as "Age" or "Yield," or a number (without quotation marks) /// that represents the position of the column within the list: /// 1 for the first column, 2 for the second column, and so on. /// </para> /// <para> /// Criteria is the range of cells that contains the conditions you /// specify. You can use any range for the criteria argument, /// as long as it includes at least one column label and at least /// one cell below the column label in which you specify a condition for the column. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); if (((args[0] == null) || (args[1] == null)) || (args[2] == null)) { throw new ArgumentNullException(); } CalcArray database = CalcConvert.ToArray(args[0]); object field = args[1]; CalcArray criteria = CalcConvert.ToArray(args[2]); double num = 0.0; if (CalcHelper.ArgumentExists(args, 1)) { IEnumerator enumerator = new DatabaseEnumerator(database, field, criteria); while (enumerator.MoveNext()) { if (enumerator.Current != null) { num++; } } } else { IEnumerator enumerator2 = new DatabaseEnumerator(database, criteria); while (enumerator2.MoveNext()) { num++; } } return(CalcConvert.ToResult(num)); }
/// <summary> /// Estimates the standard deviation of a population based on a /// sample by using the numbers in a field (column) of records /// in a list or database that match conditions that you specify. /// </summary> /// <param name="args"><para> /// The args contains 3 items: database, field, criteria. /// </para> /// <para> /// Database is the range of cells that makes up the list or database. /// A database is a list of related data in which rows of related /// information are records, and columns of data are fields. /// The first row of the list contains labels for each column. /// </para> /// <para> /// Field indicates which column is used in the function. /// Enter the column label enclosed between double quotation marks, /// such as "Age" or "Yield," or a number (without quotation marks) /// that represents the position of the column within the list: /// 1 for the first column, 2 for the second column, and so on. /// </para> /// <para> /// Criteria is the range of cells that contains the conditions you /// specify. You can use any range for the criteria argument, /// as long as it includes at least one column label and at least /// one cell below the column label in which you specify a condition for the column. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); if (((args[0] == null) || (args[1] == null)) || (args[2] == null)) { throw new ArgumentNullException(); } CalcArray database = CalcConvert.ToArray(args[0]); object field = args[1]; CalcArray criteria = CalcConvert.ToArray(args[2]); double num = 0.0; double num2 = 0.0; double num3 = 0.0; IEnumerator enumerator = new DatabaseEnumerator(database, field, criteria); while (enumerator.MoveNext()) { object current = enumerator.Current; if (CalcConvert.IsNumber(current)) { double num4; if (!CalcConvert.TryToDouble(current, out num4, true)) { return(CalcErrors.Value); } num += num4; num2 += num4 * num4; num3++; } else if (CalcConvert.IsError(current)) { return(current); } } if (num3 <= 1.0) { return(CalcErrors.DivideByZero); } return(CalcConvert.ToResult(Math.Sqrt(Math.Max((double)0.0, (double)(((num3 * num2) - (num * num)) / (num3 * (num3 - 1.0))))))); }
/// <summary> /// Extracts a single value from a column of a list or database /// that matches conditions that you specify. /// </summary> /// <param name="args"><para> /// The args contains 3 items: database, field, criteria. /// </para> /// <para> /// Database is the range of cells that makes up the list or database. /// A database is a list of related data in which rows of related /// information are records, and columns of data are fields. /// The first row of the list contains labels for each column. /// </para> /// <para> /// Field indicates which column is used in the function. /// Enter the column label enclosed between double quotation marks, /// such as "Age" or "Yield," or a number (without quotation marks) /// that represents the position of the column within the list: /// 1 for the first column, 2 for the second column, and so on. /// </para> /// <para> /// Criteria is the range of cells that contains the conditions you /// specify. You can use any range for the criteria argument, /// as long as it includes at least one column label and at least /// one cell below the column label in which you specify a condition for the column. /// </para></param> /// <returns> /// A <see cref="T:System.Object" /> value that indicates the evaluate result. /// </returns> public override object Evaluate(object[] args) { base.CheckArgumentsLength(args); if (((args[0] == null) || (args[1] == null)) || (args[2] == null)) { throw new ArgumentNullException(); } CalcArray database = CalcConvert.ToArray(args[0]); object field = args[1]; CalcArray criteria = CalcConvert.ToArray(args[2]); object current = null; IEnumerator enumerator = new DatabaseEnumerator(database, field, criteria); if (enumerator.MoveNext()) { current = enumerator.Current; if (enumerator.MoveNext()) { return(CalcErrors.Number); } return(current); } return(CalcErrors.Value); }