1

I have a class called Functions which is in the namespace, let's say SomeNameSpace. In the Functions class I have a function called GetCurrentValue which I am using to create an excel formula to display in the formula bar. I want the formula equation to start with =SomeNameSpace.Functions.GetCurrentValue but when I try this

using System.IO;
using System;

namespace SomeNameSpace{
  public class Functions{
     public object GetCurrentValue (arg1, arg2...){
     //GetCurrentValue method implementation
     }
  }
}

using System.IO;
using System;
using SomeNameSpace;

namespace AnotherNamespace{
public static bool SetFormula (string newFormula){ //newFormula value is "GetCurrentValue"        
    string sTemp = "=SomeNameSpace.Functions.";
    string Formula = sTemp + newFormula;
    return true;        
}

Formula only gets set to =GetCurrentValue. I also realized that when I change sTemp to a string other than =SomeNameSpace.Functions., for example, =SomeSpace.Functions., it works perfect, as in Formula gets set to =SomeSpace.Functions.GetCurrentValue.

Can anyone help me understand why this is happening and, if possible, how I can get to do what I want?

Kendall Frey
  • 43,130
  • 20
  • 110
  • 148
Nelly Sugu
  • 146
  • 7
  • 1
    You're never assigning `Formula` to anything. Do you need to? – Kendall Frey Sep 26 '13 at 11:49
  • Why do you have the `name-collision` tag? I don't see any naming conflicts. – Kendall Frey Sep 26 '13 at 11:55
  • you haven't declared `Formula` variable. Also, why is your `SetFormula` of boolean type and why is your `GetCurrentValue` object? –  Sep 26 '13 at 11:58
  • @KendallFrey can you not clearly see a name collision related problem? wow –  Sep 26 '13 at 11:59
  • @mehow All I see is `SomeNameSpace.Functions` and `AnotherNamespace.???`. There is no collision there. – Kendall Frey Sep 26 '13 at 12:01
  • @mehow I forgot to put the line there but right before assigning the value to Formula is had it set to null. – Nelly Sugu Sep 26 '13 at 12:11
  • Maybe it's because Excel has that name built-in and tweaks the formula (by the way, how are you outputting the formula to the formula bar?)... Which particular name are you using to trigger the conflict? – C.B. Sep 26 '13 at 13:22
  • @C.B. I doubt excel has this name. About how I am outputting the formula to the formula bar, I didn't write the whole implementation of the SetFormula method because it is too long, but inside of it I have an Excel Range "rg" for which, after getting its row and column information, I update its Formula property using the value of my Formula string. And since I have my application DisplayFormulaBar property set to true, the formula bar gets populated by the value in rg.Formula – Nelly Sugu Sep 26 '13 at 13:49
  • I finally figured it out! I tried and summarized it here http://www.josephnellysugusugira.com/excel-udf-names-conflict/ – Nelly Sugu Mar 28 '14 at 07:00
  • @JosephSuguSuguSugira Sadly the link you posted seems to no longer work. It'd be best to post it as an answer on your own (this) question. – Jeff B Oct 15 '15 at 20:27

0 Answers0