将 VB6 模块转换为 VB.NET
我几乎已经完成了从 VB6 到 VB.NET 的模块转换,但我在使用以下 2 个引号时遇到了问题,并且想知道是否有任何方法可以解决此问题:
Structure AUDINPUTARRAY
bytes(5000) As Byte
End Structure
我正在尝试将该字节行更改为: Dim字节(5000)作为字节 但它不允许我定义结构的大小。
这是第二个:
Private i As Integer, j As Integer, msg As String * 200, hWaveIn As integer
我不知道如何转换:msg As String * 200
I'm almost done converting a module from VB6 to VB.NET, but I'm having trouble with the following 2 quotes and am wondering if there's any way to go about this:
Structure AUDINPUTARRAY
bytes(5000) As Byte
End Structure
I'm trying to change that bytes line to: Dim bytes(5000) as Byte
but it's not letting me define the size in a structure.
Here's the second one:
Private i As Integer, j As Integer, msg As String * 200, hWaveIn As integer
I haven't a clue on how to convert: msg As String * 200
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法在 VB.Net 中声明初始大小,您可以稍后在构造函数中或任何需要的地方使用 Redim 语句设置其大小。
在 Visual Basic .NET 中,您无法将字符串声明为具有固定长度,除非您在宣言。前面示例中的代码会导致错误。
您声明一个没有长度的字符串。当您的代码为字符串赋值时,该值的长度决定了字符串的长度
请参阅 http://msdn.microsoft.com/ en-us/library/f47b0zy4%28v=vs.71%29.aspx
。所以你的声明将变成
you cannot declare an initial size in VB.Net , you can set its size later using Redim statement in constructor or wherever needed
In Visual Basic .NET, you cannot declare a string to have a fixed length unless you use the VBFixedStringAttribute Class attribute in the declaration. The code in the preceding example causes an error.
You declare a string without a length. When your code assigns a value to the string, the length of the value determines the length of the string
see http://msdn.microsoft.com/en-us/library/f47b0zy4%28v=vs.71%29.aspx
. so your declarration will become
您可以通过属性来做到这一点
You can do this via attributes
我建议,在将代码从 VB6 重构为 .net 时,您再考虑一下是否要模拟固定长度的
msg As String * 200
。如果您指望固定长度的字符串,以便可以从末尾截去字符,并且仍然有 200 个字符的记录,那么这就是依赖于函数副作用的混乱代码。当我们从 VB6 转换(仍在进行中)时,如果我们将字符串显式设置为 200 字节的空格块,则代码的意图会更清晰。也许可以通过声明:
String msg = String(' ', 200)
(如果这在 VB.net 和 C# 中都有效)。
I would suggest that, while refactoring your code from VB6 to .net, that you take another look at whether you even want to emulate the fixed-length
msg As String * 200
. If you were counting on the fixed-length string so that you could chop characters off of the end, and still have a 200-character record, that's messy code that depends on a function's side effects.When we converted from VB6 (a still-ongoing process), it made the intent of the code clearer if we explicitly set the string to a 200-byte block of spaces. Perhaps by declaring:
String msg = String(' ', 200)
(if that's valid in VB.net as well as C#).