Trying to replace functions of a .xla with C# dll

Jun 28 2010 6:28 AM
Hi, I may be getting ahead of myself but being new to C# I wanted to try to migrate the Excel functions I may have written in xla's etc., into a dll or two. Below is the code behind the simple MyMethods.dll I have built (please excuse the code - I'm merely playing at the moment). I've enabled COM visibility (both in the code and under properties), registered it for COM interop, and I've found that it's discoverable by Excel in the Tools/References section, but I am struggling to use it like a normal function (ie x=kgsToStonesAndLbs(80)).  In the Object Browser in Excel (F2) I can see the MyMethods library and the WeightConversion Class but no sign of the two functions/methods within - what have I missed please?

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace MyMeths

{

[System.Runtime.InteropServices.ComVisible(true)]

public class WeightConversion

{

public double kgsToStonesAndLbs(double kgs)

{

double onlyLbs = kgs * 2.2;

return onlyLbs;

}

public string kgsToStonesAndLbs(double kgs, bool lbs)

{

double kg2st = 0.157473044;

string stonesAndLbs = Convert.ToString(Math.Truncate(kgs * kg2st)) + " st." + Math.Round((kgs * kg2st - Math.Truncate(kgs * kg2st)) * 14) + " lbs.";

return stonesAndLbs;

}

}

}



Edit: I've also tried public partial class WeightConversion combined with public static string kgsToStonesAndLbs(double kgs, bool lbs) but with no apparent success. And I forgot to mention I'm using VS2008 on 3.5 .NET.