请教怎么读取BIN(二进制文件)数据到数据库
1 2 3 4 5 6 7 8 9 a b c d e f 09 14 13 07 09 12 09 12 11 12 14 08 12 12 23
这时bin文件的格式,一行16个字节
我的数据是这样,有个帧头判断字节,帧尾判断字节 ,一帧数据25个字节,怎么将他们保存到相关的数据库表中
20081119.rar
(699 Bytes)
Option Explicit Public Type 帧结构 帧头 As Integer 帧数据(0 To 15) As Byte 帧尾 As Long End Type Public Const 帧头数据 = 2816 Public Const 帧尾数据 = 51 Public Sub 打开文件(filename As String, dat() As 帧结构) Dim fj As Long Dim dattmp As 帧结构 Dim i As Long Dim count As Long i = FileLen(filename) count = i / 22 '计算记录总数 ReDim dat(count - 1) fj = FreeFile() '以只读固定长度的随机文件打开 Open filename For Random Access Read As #fj Len = 22 '2 + 16 + 4 每帧长度,注意本程序没有校验数据文件是否损坏 For i = 1 To count Get fj, , dat(i - 1) Next i Close fj End Sub
Private Sub Command1_Click() Dim 数据() As 帧结构 Call 打开文件(Text1.Text, 数据()) '下面是显示数据,没有进行数据校验 Dim i As Long Dim j As Long Dim k As String Dim m As String For i = 0 To UBound(数据) k = "" For j = 0 To 15 m = Hex(数据(i).帧数据(j)) If Len(m) = 1 Then m = "0" & m k = k & m & " " Next j List1.AddItem k Next i End Sub