【发布时间】:2013-03-22 01:43:11
【问题描述】:
我正在尝试转换读取二进制文件的 VB6 应用程序。我列出了我尝试使用的 VB6 和转换后的 VB.Net 代码。我已经尝试了所有我能想到的方法,但我要么无法在流的末尾读取,要么无法确定数组类型,因为它什么都没有。请帮忙! p>
'#################### 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
【问题讨论】:
-
也许您应该只使用 BinaryReader 类而不是将 vb 程序转换为 vb.net 代码:msdn.microsoft.com/en-us/library/system.io.binaryreader.aspx
-
同意。并非所有的 VB6 都必须逐行转换为 VB.NET。 Microsoft 将 VB 置于 .NET 中是有原因的。
-
我明白了,但我需要先从文件中取出数据。
标签: vb.net vb6 binaryfiles vb6-migration