VB读2进制文件

我的2进制文件很大,有1.96兆;其中数据格式如下:240Byte个帧头然后后面是有效数据,现在是这个文件有几百个帧,怎么读取有效数据到数组,然后显示到波形,请提供思路
2楼的回答,我的是每个帧都有头文件,还有就是把每个帧的有效数据都保存到了BData么?就比如文件格式:
第1帧:头文件(240Byte)有效数据(32Bit)
第2帧:头文件(240Byte)有效数据(32Bit)
第3帧:头文件(240Byte)有效数据(32Bit)
。。。。
第2800帧:头文件(240Byte)有效数据(32Bit)

使用二进制方式打开文件,使用seek语句定位到241位置,然后开始读取数据就可以了,比如:
Dim iFile as integer
dim BData(1 to 你的每个数据帧的大小) AS Byte

iFile=FreeFile()
open "你的数据文件名" For Binary AS #iFile
Seek #iFile,241
while Not EOF(iFile)
Get #iFile,每个数据帧的大小的数字,BData
'你的数据处理代码

Wend

Close #iFile

======================================
根据你的补充的信息,程序如下改动:

Dim iFile as integer
dim BData(1 to 4) AS Byte '因为你的数据是32位,因此是4个字节

iFile=FreeFile()
open "你的数据文件名" For Binary AS #iFile
Seek #iFile,241
while Not EOF(iFile)
Get #iFile,4,BData
if Not EOF(iFile) Then
'你的数据处理代码 ,当前帧有效数据存放在BData中

Seek #iFile,Seek(iFile)+240 '定位下一个帧有效数据位置
end if
Wend

Close #iFile
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-05-24
先定义一个自定义类型读取你的帧
Private Type zhen
Dim shuju(1 To 100) As Byte '或其他
End Type
Private Sub Command1_Click()
Dim xx() As zhen, yy(240) As Byte, kk As Long
ReDim xx(kk)'如果数据要保留就是用数组,不保留则不需要数组
Open "c:\shuju.bin" For Binary As #1
Get #1, , yy()
While Not EOF(1)
kk = kk + 1
If UBound(xx) < kk Then ReDim Preserve xx(kk)
Get #1, , xx(kk)
Wend
Close
End Sub
第2个回答  2009-05-24
使用二进制方式打开文件,使用seek语句定位到241位置,然后开始读取数据就可以了,比如:
Dim iFile as integer
dim BData(1 to 你的每个数据帧的大小) AS Byte

iFile=FreeFile()
open "你的数据文件名" For Binary AS #iFile
Seek #iFile,241
while Not EOF(iFile)
Get #iFile,每个数据帧的大小的数字,BData
'你的数据处理代码

Wend

Close #iFile

回答者: Null_bd - 副总裁 十级 5-24 11:15
相似回答
大家正在搜