将VB6 Open For Binary转换为VB.Net(固定字符串数组)
我正在尝试转换一个读取二进制文件的VB6应用程序。我已经列出了VB6和我试图使用的转换后的VB.Net代码。我已经尝试了我能想到的一切,我要么无法读取流的末尾,要么无法确定数组类型,因为它什么都不是。请帮忙将VB6 Open For Binary转换为VB.Net(固定字符串数组),vb.net,vb6,binaryfiles,vb6-migration,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 Stri
'#################### 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
来自来自现场现场码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码码毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫毫####
专用常量数字输出=24
Private Const PAUSES=8
Private PLabel(暂停-1)为字符串*30
私有EventLab(DIGITALOUTS-1)作为字符串*20
私有子读取文件()
将文件号设置为整数
FileNumber=FreeFile
打开二进制文件的“C:\TEST.BAT”作为#文件号
获取#FileNumber,3000,PLabel'自动暂停指令标签
获取#文件号、3500、EventLab的数字输出通道标签
关闭#文件编号
端接头
本月月月日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日日####
专用常量数字输出为短=24
Private Const暂停为Short=8
Dim PLabel()作为字符串
Dim EventLab()作为字符串
私有子读取文件()
Dim f作为Short=FreeFile()
FileOpen(f,“C:\TEST.BAT”,OpenMode.Binary)
FileGet(f,PLabel,3000)“自动暂停指令标签我找到了答案
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
Private Const digitalout As Short=24
Private Const暂停为Short=8
私有结构暂停
Dim Label()作为字符串
端部结构
私有结构数字
Dim Label()作为字符串
端部结构
调暗面板(暂停-1)作为暂停
Dim EventLab(DIGITALOUTS-1)作为数字
私有子读取文件()
Dim f作为Short=FreeFile()
FileOpen(f,“C:\Test.BAT”,OpenMode.Binary)
FileGet(f,PLabel,3000)“自动暂停指令标签
FileGet(f、EventLab、3500)数字输出通道标签
文件关闭(f)
端接头
也许您应该使用BinaryReader类,而不是将vb程序转换为vb.net代码:同意。并非所有VB6都必须逐行转换为VB.NET。微软把VB放进.NET是有原因的。我明白了,但我需要先从文件中取出数据。