Excel DNA Concatenate multiple looked values

Mar 4, 2015 at 7:49 PM
Greetings!
As the titles states, I'm trying to define a function that return all the values that had been found by looking one user specified value in a column and returning the value next to it.
Something like this;
Value: 213
Col A Col B
213 1
122 3
213 5
Function would need to result in "1 5"
My code is:
<DnaLibrary Language="CS">
  <Reference AssemblyPath="System.Windows.Forms.dll"/>
   <![CDATA[
   using System;
   using System.Windows.Forms;
   using ExcelDna.Integration;
   using System.Collections.Generic;

   public class MyAddIn : IExcelAddIn
   {
    public void AutoOpen()
    {
     MessageBox.Show("Succeed on loading formulas used!");
    }
    
    public void AutoClose()
    {
     MessageBox.Show("Don't Unload the formulas!");
    }
   }
public class MyFunctions

    {

    [ExcelFunction(Description="Joins ALL values found in an Array from a value cell found in a column ", Category="Example1")]
    public static object LookUpConcat(object x,object[,] cells,object[,] cells2)
    {
    List<string> list = new List<string>();
List<string> list2 = new List<string>();

    foreach (object o in cells)

{
int i=+1;
int j=0;
if ( !(o is ExcelEmpty) && o.Equals(x) )

    foreach (object y in cells2)
{
j=+1;
if ( !(y is ExcelEmpty) && i.Equals(j))
list2.Add(y.ToString()); 
}

}

    return string.Join(" ", list2.ToArray());

    }
}
    ]]>
</DnaLibrary>
However, when this is evaluated returns: 1 3 5 1 3 5
I used the i and j counters to evaluate when they were on the same position, but, it doesn't seem to work.
Mar 4, 2015 at 8:02 PM
Edited Mar 6, 2015 at 7:25 PM
Solved
<DnaLibrary Language="CS">
  <Reference AssemblyPath="System.Windows.Forms.dll"/>
   <![CDATA[
   using System;
   using System.Windows.Forms;
   using ExcelDna.Integration;
   using System.Collections.Generic;
   // This class implements the ExcelDna.Integration.IExcelAddIn interface.
   // This allows the add-in to run code at start-up and shutdown.
   public class MyAddIn : IExcelAddIn
   {
    public void AutoOpen()
    {
     MessageBox.Show("Succeed on loading formulas!");
    }
    
    public void AutoClose()
    {
     MessageBox.Show("Don't Unload the formulas!");
    }
   }
public class MyFunctions
    {

[ExcelFunction(Description = "Joins ALL values found in an Array from a value cell found in a column Syntax Available on Training", Category = "Example1")]
        public static object LookUpConcat(object Lookup_value, object[,] Lookup_vector, object[,] Result_vector, string Charactertodivide, bool MatchWhole, bool UniqueOnly)
        {
            int i = 0;
            int j = 0;
            string text1;
            string text2;
            string text3;
            text2 = Lookup_value.ToString();
            List<string> list = new List<string>();
            List<string> list2 = new List<string>();

            foreach (object o in Lookup_vector)
                
            {
                text1 = o.ToString();
                Console.WriteLine(++i);
                j = 0;
                if (!(o is ExcelEmpty))
                    
                    foreach (object y in Result_vector)
                    {
                        text3 = y.ToString();
                        Console.WriteLine(++j);
                        if (!(y is ExcelEmpty) && i.Equals(j) && !(MatchWhole.Equals(true)) && text1.Contains(text2) && !(UniqueOnly.Equals(true)))
                            list2.Add(y.ToString());
                        if (!(y is ExcelEmpty) && i.Equals(j) && (MatchWhole.Equals(true)) && text1.Equals(text2) && !(UniqueOnly.Equals(true)))
                            list2.Add(y.ToString());
                        if (!(y is ExcelEmpty) && i.Equals(j) && !(MatchWhole.Equals(true)) && !(list2.Contains(text3)) && (UniqueOnly.Equals(true)))
                            list2.Add(y.ToString());
                        if (!(y is ExcelEmpty) && i.Equals(j) && (MatchWhole.Equals(true)) && text1.Equals(text2) && !(list2.Contains(text3)) && (UniqueOnly.Equals(true)))
                            list2.Add(y.ToString());
                    }

            }


return string.Join(Charactertodivide, list2.ToArray());

    }

}
    ]]>

</DnaLibrary>
Syntax =lookupconcat(value to look, range to look, range to return, character that separates them.
The fifth argument, a Boolean, determines whether the lookup should be trying to match the entire cell value or only part of the cell value
(the default value is False meaning the lookup will have to match only part of the cell value).
The sixth argument, a Boolean, determines if the concatenated list that is returned should allow duplicated values
to be listed or whether a found value should only be listed one time, that being the first occurrence in the range
(the default value is False meaning found values will be listed as many times as they are found within the search
range).
As you may google, this function was developed by someone else.
PS: There's some mistake in some statment -I think it's about uniques-
Marked as answer by Sgdva on 3/6/2015 at 12:13 PM