将VB6 Open for Binary转换为VB.Net(固定字符串数组)

时间:2013-03-20 19:01:34

标签: vb.net vb6 binaryfiles vb6-migration

我正在尝试转换读取二进制文件的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

1 个答案:

答案 0 :(得分: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