Structure typ050 <VBFixedString(1)> Dim ID As String <VBFixedString(1)> Dim 支払請求区分 As String <VBFixedString(1)> Dim 陸海貨区分 As String <VBFixedString(2)> Dim 料率区分 As String <VBFixedString(7)> Dim 設定車系 As String <VBFixedString(3)> Dim 車系区分 As String End Structure Structure typ050File Private Const Record_LENGTH As Integer = 144 Dim Record As HS21.Shuttle.lang.FixedLengthString Public Sub New(ByVal Null As Integer) Record = New HS21.Shuttle.lang.FixedLengthString(Record_LENGTH) Record.Value = Space(Record_LENGTH) End Sub End Structure Private o2 As typ050 Private typO2File As typ050File o2 = LSet(typO2File) 以上代码的错误点和正确改法
时间: 2024-02-14 18:18:26 浏览: 260
NUD3160LT1G-VB一种N沟道SOT23封装MOS管
以上代码存在以下错误点:
1. 缺少变量声明,例如typO2File的声明。
2. LSet函数用法错误,应该使用StructMarshal.StructureToPtr方法将typO2File转换为指针,再使用Marshal.PtrToStructure方法将指针转换为o2结构体。
正确改法如下:
```
Structure typ050
<VBFixedString(1)> Dim ID As String
<VBFixedString(1)> Dim 支払請求区分 As String
<VBFixedString(1)> Dim 陸海貨区分 As String
<VBFixedString(2)> Dim 料率区分 As String
<VBFixedString(7)> Dim 設定車系 As String
<VBFixedString(3)> Dim 車系区分 As String
End Structure
Structure typ050File
Private Const Record_LENGTH As Integer = 144
Dim Record As HS21.Shuttle.lang.FixedLengthString
Public Sub New(ByVal Null As Integer)
Record = New HS21.Shuttle.lang.FixedLengthString(Record_LENGTH)
Record.Value = Space(Record_LENGTH)
End Sub
End Structure
Dim typO2File As typ050File
Dim o2 As typ050
' 将typO2File转换为指针,并将指针转换为o2结构体
Dim ptr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typO2File))
Marshal.StructureToPtr(typO2File, ptr, False)
o2 = DirectCast(Marshal.PtrToStructure(ptr, GetType(typ050)), typ050)
Marshal.FreeHGlobal(ptr)
```
阅读全文