PV 函数以及将 VB6 移植到 C#
我正在致力于将一些经典的 VB6 代码移植到 C#,并且偶然发现了 PV
函数的用法。
我感觉错误包括对 Microsoft.VisualBasic 程序集的引用。这是常见的做法,还是我应该探索更多选择。我想到的下一个想法是探索 Reflector 中的 PV 功能。
I'm working on porting some classic VB6 code to C# and just stumbled across a usage of the PV
function.
I feels wrong including a reference to the Microsoft.VisualBasic Assembly. Is this something that is commonly done, or should I explore further options. The next idea that pops into my mind is exploring this PV function in Reflector.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
C# 和 VB.NET 中 Microsoft.VisualBasic 的使用已在 这个问题。 Microsoft.VisualBasic 命名空间完全受支持,只要 .Net 存在,它就会存在。没有理由避免它。
编辑:这说明在打字时,这个问题的其他答案是函数的不正确重新实现,以及来自代码的单人乐队不受支持的库画廊。来吧伙计们,微软要从 VB 中删除财务功能需要真正的重大事件 。
对于 Microsoft.VisualBasic.Compatibility 来说,这是一个不同的故事,它专门供 VB6 升级向导使用,编辑 现已在 .Net 4 中标记为过时< /em>(我的预测成真了),并且不应该用于新的开发。删除对此的引用会有一些优势,但就我个人而言,我可能会尝试首先引用 .Net 3.5 来实现完全工作的端口。
The use of Microsoft.VisualBasic from C# and VB.NET has been discussed thoroughly under this question. The Microsoft.VisualBasic namespace is fully supported, and will be around as long as .Net is around. There's no reason to avoid it.
EDIT: It's telling that at the time of typing, the other answers for this question are an incorrect reimplementation of the function, and a one-man-band unsupported library from Code Galleries. Come on guys, it would take a real major event for Microsoft to drop the financial functions from VB.
It's a different story for Microsoft.VisualBasic.Compatibility, which is exclusively for use by the VB6 upgrade wizard, EDIT has now been marked obsolete in .Net 4 (my prediction came true), and should not be used for new development. There would be some advantages in removing references to this, but personally I'd probably try to achieve a fully working port first referencing.Net 3.5.
在 C# 中复制非常简单,
只需重新排列 Microsoft 提供的公式< /a>.
Pretty straight forward to replicate in C#
Just a re-arrangement of the formula Microsoft provides.
您可以使用这个库来复制 f# 中的 excel 函数
Library
它的 PV 是现值。我用过一两次。只需将其放入并添加参考即可。
You could use this library that duplicates excel functions in f#
Library
It has PV which is present value. I have used it once or twice. Just drop it in and add the reference.
我尝试使用已接受的答案,但无法让它在 .NET Core 中工作。我环顾四周,在 github 上发现了这段代码,它似乎是 Microsoft 的 PV 实现:
https://github.com/microsoft/referencesource/blob/master/Microsoft.VisualBasic/runtime/msvbalib/Financial.vb#L662
您仍然会需要将其转译为 C#。如果我在本文末尾有一个足够通用的实现,我也会发布它。
I tried using the accepted answer, but I couldn't get it to work in .NET Core. I did some looking around and ran across this code on github that appears to be Microsoft's implementation of PV:
https://github.com/microsoft/referencesource/blob/master/Microsoft.VisualBasic/runtime/msvbalib/Financial.vb#L662
You'd still need to transpile it to C#. If I have a general enough implementation at the end of this I'll post that too.