11-13-2023 11:03 AM
I found a C# code library and I'd like to use this class in VB.Net. Here are the steps I've taken so far.
1. In my VB.Net Rule I've referenced the C# assemblies.
2. In my VB.Net Rule I've created a new object for the C# class
'Create an object for the class defined in External Assembly (Toolbox) so we can use methods in the class
Dim XIRRWrapper As New OneStream.BusinessRule.Finance.XIRR.CalculationWrapper
3. Now I'm able to create objects in the C# referenced assemblies in VB.Net
Dim cashFlows = New List(Of OneStream.BusinessRule.Finance.XIRR.CashFlowDates ) From
{
New OneStream.BusinessRule.Finance.XIRR.CashFlowDates(-1000, New DateTime(2017, 1, 1)),
New OneStream.BusinessRule.Finance.XIRR.CashFlowDates(500, New DateTime(2017, 7, 1)),
New OneStream.BusinessRule.Finance.XIRR.CashFlowDates(507.5, New DateTime(2018, 1, 1))
}
4. And finally able to run a function (LINE 55 which produces a warning)
api.LogMessage( XIRRWrapper.XIRR(cashFlows, 6).ToString() )
I get the correct result. However I don't like this warning. How can I write the code better to eliminate this warning?
SUCCESS
Business Rule 'XIRRusage' was compiled successfully with warnings.
1) Warning at line 55: Access of shared member, constant member, enum member or nested type through an instance; qualifying expression will not be evaluated.
NOTE: The library being used is for the XIRR function. https://github.com/klearlending/XIRR#xirr
Solved! Go to Solution.
11-13-2023 11:25 AM - edited 11-15-2023 11:59 AM
Hi Chris,
It doesn't matter that your library is written in C#. Once compiled, .net is .net.
The error is telling you that you are accessing the shared (static) method XIRR through in instance of CalculationWrapper - created when you used the New keyword.
Try this:
'Create an object for the class defined in External Assembly (Toolbox) so we can use methods in the class
'** Commented out. Don't instantiate to use a static method.
'Dim XIRRWrapper As New OneStream.BusinessRule.Finance.XIRR.CalculationWrapper
Dim cashFlows = New List(Of OneStream.BusinessRule.Finance.XIRR.CashFlowDates ) From
{
New OneStream.BusinessRule.Finance.XIRR.CashFlowDates(-1000, New DateTime(2017, 1, 1)),
New OneStream.BusinessRule.Finance.XIRR.CashFlowDates(500, New DateTime(2017, 7, 1)),
New OneStream.BusinessRule.Finance.XIRR.CashFlowDates(507.5, New DateTime(2018, 1, 1))
}
api.LogMessage(OneStream.BusinessRule.Finance.XIRR.CalculationWrapper.XIRR(cashFlows, 6).ToString())
11-13-2023 11:46 AM
Hi Robb,
Thank you! The warning is gone. Business Rule 'XIRRusage' was compiled successfully.
api.LogMessage( OneStream.BusinessRule.Finance.XIRR.CalculationWrapper.XIRR(cashFlows, 6).ToString() )
11-13-2023 11:25 AM - edited 11-15-2023 11:59 AM
Hi Chris,
It doesn't matter that your library is written in C#. Once compiled, .net is .net.
The error is telling you that you are accessing the shared (static) method XIRR through in instance of CalculationWrapper - created when you used the New keyword.
Try this:
'Create an object for the class defined in External Assembly (Toolbox) so we can use methods in the class
'** Commented out. Don't instantiate to use a static method.
'Dim XIRRWrapper As New OneStream.BusinessRule.Finance.XIRR.CalculationWrapper
Dim cashFlows = New List(Of OneStream.BusinessRule.Finance.XIRR.CashFlowDates ) From
{
New OneStream.BusinessRule.Finance.XIRR.CashFlowDates(-1000, New DateTime(2017, 1, 1)),
New OneStream.BusinessRule.Finance.XIRR.CashFlowDates(500, New DateTime(2017, 7, 1)),
New OneStream.BusinessRule.Finance.XIRR.CashFlowDates(507.5, New DateTime(2018, 1, 1))
}
api.LogMessage(OneStream.BusinessRule.Finance.XIRR.CalculationWrapper.XIRR(cashFlows, 6).ToString())
11-13-2023 11:46 AM
Hi Robb,
Thank you! The warning is gone. Business Rule 'XIRRusage' was compiled successfully.
api.LogMessage( OneStream.BusinessRule.Finance.XIRR.CalculationWrapper.XIRR(cashFlows, 6).ToString() )
01-09-2024 05:53 AM
Hi Chris_Rothermel
Have you done a lot of these refs in your application? Have you seen performance issues as a result of reference C# in VB.NET codes? Cheers
01-09-2024 10:26 AM
Hi cbriscoe,
I've used the direct reference to functions to simplify my code in other calculations. I've seen no performance differences between coding in C# versus VB.Net. The biggest single performance issue I've seen is when people code and then loop through multiple hierarchies looking for data intersections. Much better is to use and understand Data Buffer calculations (including unbalanced data buffer arithmetic which needs some improvements in usability).
I went another direction on this XIRR journey -- one that was simpler to code and uses the Microsoft IRR function as the solution basis. I posted that code in the forum.
OneStream.BusinessRule.Finance.XIRR.Function here...
OneStream business rules is my favorite part of the platform and I'm learning more about it everyday.
01-09-2024 11:07 AM
Cheers for you reply Chris. I have some C# vs VB.NET Snippet in case you are interested.
04-22-2024 10:59 AM
hi Chris, I am in need of similar code for XIRR, can you point me to the post that you mention? I'm not seeing the link. thanks, Greg
"I went another direction on this XIRR journey -- one that was simpler to code and uses the Microsoft IRR function as the solution basis. I posted that code in the forum."
04-22-2024 11:18 AM
04-23-2024 05:22 AM
Chris, I like your code, Is all good now? Yes? Cheers to Jack.
04-23-2024 10:26 AM
Glad you like it cbriscoe! All good with me, @GregHertling?
04-24-2024 09:31 AM
hi Chris, it seems to be working well. thanks for the help!