关于如何处理二进制数据?

0004yhy4000 2003-07-29 04:55:54
我有一些二进制数据!想通过VB处理!例如:分析数据或者画出数据曲线等等!不知该如何处理!哪里有这方面的资料?或者类似的程序在那里可以找到?请各位高人指点一二!小弟先谢谢了!
...全文
38 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
龙华 2003-08-05
  • 打赏
  • 举报
回复
太笼统了。
kmzs 2003-08-04
  • 打赏
  • 举报
回复
什么呀???
Fnems 2003-08-03
  • 打赏
  • 举报
回复
说详细点嘛。什么数据?和什么有关?要怎么处理?(统计?计算?)
gpo2002 2003-08-01
  • 打赏
  • 举报
回复
The following routines demonstrate how to write/read data to/from a file. The data can be an array or any simple data type.
Option Explicit
'Purpose : Saves/writes a block of data to a file
'Inputs : vData The data to store in the file. Can be an
' array or any simple data type.
' sFileName The path and file name where the data is to be stored
' [bAppendToFile] If True will append the data to the existing file
'Outputs : Returns True if succeeded in saving data
'Author : Andrew Baker
'Date : 09/03/2001 14:32
'Notes :
'Revisions :
Function FileWriteBinary(vData As Variant, sFileName As String, Optional bAppendToFile As Boolean = True) As Boolean
Dim iFileNum As Integer, lWritePos As Long
On Error GoTo ErrFailed
If bAppendToFile = False Then
If Len(Dir$(sFileName)) > 0 And Len(sFileName) > 0 Then
'Delete the existing file
VBA.Kill sFileName
End If
End If
iFileNum = FreeFile
Open sFileName For Binary Access Write As #iFileNum
If bAppendToFile = False Then
'Write to first byte
lWritePos = 1
Else
'Write to last byte + 1
lWritePos = LOF(iFileNum) + 1
End If
Put #iFileNum, lWritePos, vData
Close iFileNum
FileWriteBinary = True
Exit Function
ErrFailed:
FileWriteBinary = False
Close iFileNum
Debug.Print Err.Description
End Function
'Purpose : Reads the contents of a binary file
'Inputs : sFileName The path and file name where the data is stored
'Outputs : Returns an array containing all the data stored in the file.
' e.g. ArrayResults(1 to lNumDataBlocks)
' Where lNumDataBlocks is the number of data blocks stored in file.
' If the file was created using FileWriteBinary, this will be the number
' of times data was appended to the file.
'Author : Andrew Baker
'Date : 09/03/2001 14:32
'Notes :
'Revisions :
Function FileReadBinary(sFileName As String) As Variant
Dim iFileNum As Integer, lFileLen As Long
Dim vThisBlock As Variant, lThisBlock As Long, vFileData As Variant
On Error GoTo ErrFailed
If Len(Dir$(sFileName)) > 0 And Len(sFileName) > 0 Then
iFileNum = FreeFile
Open sFileName For Binary Access Read As #iFileNum
lFileLen = LOF(iFileNum)
Do
lThisBlock = lThisBlock + 1
Get #iFileNum, , vThisBlock
If IsEmpty(vThisBlock) = False Then
If lThisBlock = 1 Then
ReDim vFileData(1 To 1)
Else
ReDim Preserve vFileData(1 To lThisBlock)
End If
vFileData(lThisBlock) = vThisBlock
End If
Loop While EOF(iFileNum) = False
Close iFileNum
FileReadBinary = vFileData
End If
Exit Function
ErrFailed:
Close iFileNum
Debug.Print Err.Description
End Function
'Demonstration routine
Sub Test()
Dim avValues() As Long, lThisRow As Long
Dim avFileData As Variant, vThisBlock As Variant, vThisSubBlock As Variant
Dim lThisBlock As Long
'Create an array of numbers
ReDim avValues(1 To 10)
For lThisRow = 1 To 10
avValues(lThisRow) = lThisRow
Next
'Write the array to a file
If FileWriteBinary(avValues, "C:\Test.dat") Then
'Read the data back from the file
avFileData = FileReadBinary("C:\Test.dat")
If IsArray(avFileData) Then
'Print data
Debug.Print "Values returned:"
For Each vThisBlock In avFileData
lThisBlock = lThisBlock + 1
Debug.Print "Data Set:" & CStr(lThisBlock)
For Each vThisSubBlock In vThisBlock
Debug.Print vThisSubBlock
Next
Next
'Completed
MsgBox "The array has been successfully retrieved!", vbInformation
End If
End If
End Sub
0004yhy4000 2003-07-30
  • 打赏
  • 举报
回复
up!

742

社区成员

发帖
与我相关
我的任务
社区描述
VB 版八卦、闲侃,联络感情地盘,禁广告帖、作业帖
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧