private ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval lookupEval, ValueEval indexEval, ValueEval returnEval, String notFound, LookupUtils.MatchMode matchMode, LookupUtils.SearchMode searchMode, bool isSingleValue) { try { ValueEval lookupValue = OperandResolver.GetSingleValue(lookupEval, srcRowIndex, srcColumnIndex); TwoDEval tableArray = LookupUtils.ResolveTableArrayArg(indexEval); int matchedRow; try { matchedRow = LookupUtils.XlookupIndexOfValue(lookupValue, LookupUtils.CreateColumnVector(tableArray, 0), matchMode, searchMode); } catch (EvaluationException e) { if (ErrorEval.NA.Equals(e.GetErrorEval())) { if (string.IsNullOrEmpty(notFound)) { if (returnEval is AreaEval) { AreaEval area = (AreaEval)returnEval; int width = area.Width; if (isSingleValue || width <= 1) { return(new StringEval(notFound)); } return(new NotFoundAreaEval(notFound, width)); } else { return(new StringEval(notFound)); } } return(ErrorEval.NA); } else { return(e.GetErrorEval()); } } if (returnEval is AreaEval) { AreaEval area = (AreaEval)returnEval; if (isSingleValue) { return(area.GetRelativeValue(matchedRow, 0)); } return(area.Offset(matchedRow, matchedRow, 0, area.Width - 1)); } else { return(returnEval); } } catch (EvaluationException e) { return(e.GetErrorEval()); } }
private ValueEval _evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) { if (args.Length < 2) { return(ErrorEval.VALUE_INVALID); } LookupUtils.MatchMode matchMode = LookupUtils.MatchMode.ExactMatch; if (args.Length > 2) { try { ValueEval matchModeValue = OperandResolver.GetSingleValue(args[2], srcRowIndex, srcColumnIndex); int matchInt = OperandResolver.CoerceValueToInt(matchModeValue); matchMode = LookupUtils.GetMatchMode(matchInt); } catch (EvaluationException e) { return(e.GetErrorEval()); } catch (Exception e) { return(ErrorEval.VALUE_INVALID); } } LookupUtils.SearchMode searchMode = LookupUtils.SearchMode.IterateForward; if (args.Length > 3) { try { ValueEval searchModeValue = OperandResolver.GetSingleValue(args[3], srcRowIndex, srcColumnIndex); int searchInt = OperandResolver.CoerceValueToInt(searchModeValue); searchMode = LookupUtils.GetSearchMode(searchInt); } catch (EvaluationException e) { return(e.GetErrorEval()); } catch (Exception e) { return(ErrorEval.VALUE_INVALID); } } return(evaluate(srcRowIndex, srcColumnIndex, args[0], args[1], matchMode, searchMode)); }
private ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval lookupEval, ValueEval indexEval, LookupUtils.MatchMode matchMode, LookupUtils.SearchMode searchMode) { try { ValueEval lookupValue = OperandResolver.GetSingleValue(lookupEval, srcRowIndex, srcColumnIndex); TwoDEval tableArray = LookupUtils.ResolveTableArrayArg(indexEval); ValueVector vector; if (tableArray.IsColumn) { vector = LookupUtils.CreateColumnVector(tableArray, 0); } else { vector = LookupUtils.CreateRowVector(tableArray, 0); } int matchedIdx = LookupUtils.XlookupIndexOfValue(lookupValue, vector, matchMode, searchMode); return(new NumberEval((double)matchedIdx + 1)); } catch (EvaluationException e) { return(e.GetErrorEval()); } }
private ValueEval _evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex, bool isSingleValue) { if (args.Length < 3) { return(ErrorEval.VALUE_INVALID); } String notFound = null; if (args.Length > 3) { try { ValueEval notFoundValue = OperandResolver.GetSingleValue(args[3], srcRowIndex, srcColumnIndex); String notFoundText = LaxValueToString(notFoundValue); if (notFoundText != null) { String trimmedText = notFoundText.Trim(); if (trimmedText.Length > 0) { notFound = trimmedText; } } } catch (EvaluationException e) { return(e.GetErrorEval()); } } LookupUtils.MatchMode matchMode = LookupUtils.MatchMode.ExactMatch; if (args.Length > 4) { try { ValueEval matchModeValue = OperandResolver.GetSingleValue(args[4], srcRowIndex, srcColumnIndex); int matchInt = OperandResolver.CoerceValueToInt(matchModeValue); matchMode = LookupUtils.GetMatchMode(matchInt); } catch (EvaluationException e) { return(e.GetErrorEval()); } catch (Exception) { return(ErrorEval.VALUE_INVALID); } } LookupUtils.SearchMode searchMode = LookupUtils.SearchMode.IterateForward; if (args.Length > 5) { try { ValueEval searchModeValue = OperandResolver.GetSingleValue(args[5], srcRowIndex, srcColumnIndex); int searchInt = OperandResolver.CoerceValueToInt(searchModeValue); searchMode = LookupUtils.GetSearchMode(searchInt); } catch (EvaluationException e) { return(e.GetErrorEval()); } catch (Exception) { return(ErrorEval.VALUE_INVALID); } } return(evaluate(srcRowIndex, srcColumnIndex, args[0], args[1], args[2], notFound, matchMode, searchMode, isSingleValue)); }