1

我正在尝试转换读取二进制文件的 VB6 应用程序。我列出了我尝试使用的 VB6 和转换后的 VB.Net 代码。我已经尝试了我能想到的一切,要么无法读取流的末尾,要么无法确定数组类型,因为它什么都不是。 请帮忙!

'####################  VB6 Code ####################  
Private Const DIGITALOUTS = 24
Private Const PAUSES = 8

Private PLabel(PAUSES - 1) As String * 30
Private EventLab(DIGITALOUTS - 1) As String * 20

Private Sub ReadFile()
    Dim FileNumber As Integer
    FileNumber = FreeFile
    Open "C:\TEST.BAT" For Binary As #FileNumber
    Get #FileNumber, 3000, PLabel            'automatic pausing instruction labels
    Get #FileNumber, 3500, EventLab          'digital output channel labels
    Close #FileNumber
End Sub



'####################  Converted VB.Net Code ####################  
Private Const DIGITALOUTS As Short = 24
Private Const PAUSES As Short = 8

<VBFixedArray(PAUSES - 1)> <VBFixedString(30)> Dim PLabel() As String
<VBFixedArray(DIGITALOUTS - 1)> <VBFixedString(20)> Dim EventLab() As String

Private Sub ReadFile()
    Dim f As Short = FreeFile()
    FileOpen(f, "C:\TEST.BAT", OpenMode.Binary)
    FileGet(f, PLabel, 3000) 'automatic pausing instruction labels <===Error: Unable to read beyond the end of the stream
    FileGet(f, EventLab, 3500) 'digital output channel labels
    FileClose(f)
End Sub
4

1 回答 1

2

我想到了

Private Const DIGITALOUTS As Short = 24
Private Const PAUSES As Short = 8

Private Structure Pause
    <VBFixedString(30)> Dim Label() As String
End Structure

Private Structure Digital
    <VBFixedString(20)> Dim Label() As String
End Structure

Dim PLabel(PAUSES - 1) as Pause
Dim EventLab(DIGITALOUTS - 1) as Digital

Private Sub ReadFile()
    Dim f As Short = FreeFile()
    FileOpen(f, "C:\Test.BAT", OpenMode.Binary)
    FileGet(f, PLabel, 3000) 'automatic pausing instruction labels 
    FileGet(f, EventLab, 3500) 'digital output channel labels
    FileClose(f)
End Sub
于 2013-03-21T17:42:35.657 回答