Access VBA:如何将OLE字段内容转储为字节 [英] Access VBA: how to dump OLE field content into bytes

查看:77
本文介绍了Access VBA:如何将OLE字段内容转储为字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含OLE字段的表,我想以字节为单位查看某些字段的内容。到目前为止,我只能在监视窗口中使用BinData数组查看它。
我尝试使用CByte函数将其转换为字节数组,但它
出现类型不匹配错误。

I have a table containing OLE fields and I would like to see the content of some fields as bytes. I only can view it in the Watch window with BinData array so far . I tried to convert it to a byte array using CByte function but it gives an "Type mismatch" error.

有什么方法可以获得OLE字段内容作为字节数组?

Is there any way to obtain the OLE field content as a byte array?

我的代码将字节字段内容逐字节读取到Bindata数组中:

My code which reads byte by byte field content into Bindata array:

Sub DumpField()

Dim BinData(100) As Variant
Dim r As ADODB.Recordset
Dim i As Integer

Set r = New ADODB.Recordset
With r
.CursorType = adOpenStatic
.LockType = adLockReadOnly
.Open "SELECT [fBinary] FROM tbDesc WHERE ID=100", CurrentProject.Connection
If .BOF Then MsgBox "No Records"
Exit Sub
End If

For i = 0 To r.Fields(0).ActualSize - 1
BinData(i) = r.Fields(0).GetChunk(1)
Next i

End With
End Sub


推荐答案

OLE字段内容是一个字节数组。但是,使用 CByte 会尝试将某些内容转换为单个字节,但会失败。

The OLE field content is a byte array. Using CByte, however, attempts to convert something to a single byte, and fails.

您可以打印单个字节

Debug.Print r.Fields(0).Value(0) 'First byte

或以以下方式之一存储字节数组:

Or store a byte array in one of the following ways:

1:只需使用变体

Dim BinData As Variant
BinData = r.Fields(0).Value

2:创建适当大小的字节数组,然后将字节数组设置为OLE对象值

2: create a byte array of the appropriate size, then set the byte array to the OLE objects value

Dim BinData() As Byte
Dim objSize As Long
objSize = UBound(r.Fields(0).Value)
Redim BinData(0 To objSize)
BinData = r.Fields(0).Value

这篇关于Access VBA:如何将OLE字段内容转储为字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆