Rag*_*gav 0 vb.net string vb6 vb6-migration
我只是想将VB6函数之一转换为VB.Net,下面是转换语句我面临的问题
Option Strict Off
Option Explicit On
Imports Microsoft.VisualBasic.Compatibility.VB6
Imports System
Imports System.Runtime.InteropServices
Module FunctionCmd_Msg
Public FunCommand_Msg As Fun_CommandMessage = Fun_CommandMessage.CreateInstance()
'Function Command Message
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _ _
Public Structure Fun_CommandMessage
<VBFixedString(1)> Public one As String
<VBFixedString(1)> Public two As String
<VBFixedString(3)> Public three As String
Dim five As String
<VBFixedString(8)> Public four As String
Public Shared Function CreateInstance() As Fun_CommandMessage
Dim result As New Fun_CommandMessage
result.one = String.Empty
result.two = String.Empty
result.three = String.Empty
result.four = String.Empty
result.five = String.Empty
End Function
End Structure
End Module
Run Code Online (Sandbox Code Playgroud)
假设:
one = "1"
two = "1"
three = "123"
four = "5678"
five = "testing"
FS = character (field separator)
Run Code Online (Sandbox Code Playgroud)
连接字符串我需要一个固定长度的字符串,如下所示:
one & two & FS & three & FS & five & FS & four
Run Code Online (Sandbox Code Playgroud)
输出:由于四是一个8长度的固定长度字符串,其余4个字符应填充null,如下所示
11 FS 123 FS testing FS 5678XXXX
Run Code Online (Sandbox Code Playgroud)
固定长度的字符串在.NET中根本没有任何意义.Microsoft试图提供类似的类以便于升级,但事实是您应该根据使用情况更改代码:
固定长度字符串在VB6代码中做了什么?这是没有充分理由的吗?然后String
在.NET中使用normal .
它是否与C API互操作?然后使用编组在C API调用中设置数组的大小.