title: Using Excel Built-in Functions on top of the UDF
body: <p>I don't know why for some reason the Excel built-in function <code>=SUM()</code> can't really sum up the results created by the custom UDF. It appears to always end up with 0. </p>
  
  <p>For example, I have got a following UDF, called <code>myUDF</code>, which will return the number of items. </p>
  
  <p>For the cell <code>A1</code>:<br>
  Formula: <code>=myUDF('ItemA')</code> Result: 10</p>
  
  <p>For the cell <code>B1</code>:<br>
  Formula: <code>=myUDF('ItemB')</code> Result: 15</p>
  
  <p>So When I do <code>=Sum(A1:B1)</code> and put the formula in cell <code>C1</code>, it won't return 25 but 0 instead.</p>
  
  <p>I have tried to use some data formatting stuff (converting to numeric) but still no luck there. Has anyone here had similar issue before? Any ideas on the cause of it? </p>
  
  <p>Thanks.</p>
  
  <p>EDIT:
  Code Sample</p>
  
  <pre><code>        public object MyUDF(string id, string pk, string param1 = "", string param2 = "", string param3 = "", string param4 = "")
          {
              object result = null;
              string strFormula;
  
              double n = 0;
              DateTime dt;
  
              try
              {
                  strFormula = buildFormula(id, pk, param1, param2, param3, param4);
  
                  result = ws.getServiceResultsDataString(id, objUser, pk, param1, param2, param3, param4);
  
                  if (double.TryParse(result.ToString(), out n)) 
                  {
                      result = n;
                  }
                  else if (DateTime.TryParse(result.ToString(), out dt))
                  {
                      result = dt.Date;
                  }
                  ws.Dispose();
                  objUser = null;
  
              }
              catch (Exception ex)
              {               
              }
              finally
              {   
              }
              return result;
          }
  </code></pre>