473,471 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

binary data and the OLE Object field

I need to unpack a bunch of values (Single data type) from an OLE Object
field. I think the Windows API has a CopyMemory function that could, for
example, get 4-byte chunks of the field which could then be put in an array
or table or something. Is there a way to do this in VBA? What I'd like to
end up with is a table with one field and N number of rows representing the
values unpacked from the binary data in the current OLE Object field.

Thanks in advance.
Nov 13 '05 #1
8 11197
*Air Code*
' Assumes OLE field is bound to an OLE Frame control named "olePicture"

Dim a() As Long
Dim lTemp As Long

lTemp = LenB(Me.olePicture.Value) / 4
ReDim a(0 To lTemp)

' Copy the contents of the OLE field to our array
a = Me.olePicture.Value

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"deko" <de**@hotmail.com> wrote in message
news:AC******************@newssvr13.news.prodigy.c om...
I need to unpack a bunch of values (Single data type) from an OLE Object field. I think the Windows API has a CopyMemory function that could, for example, get 4-byte chunks of the field which could then be put in an array or table or something. Is there a way to do this in VBA? What I'd like to end up with is a table with one field and N number of rows representing the values unpacked from the binary data in the current OLE Object field.

Thanks in advance.


Nov 13 '05 #2
> ' Assumes OLE field is bound to an OLE Frame control named "olePicture"

Dim a() As Long
Dim lTemp As Long

lTemp = LenB(Me.olePicture.Value) / 4
ReDim a(0 To lTemp)

' Copy the contents of the OLE field to our array
a = Me.olePicture.Value


Thanks for the reply.

The OLE field is just a field in a table, not bound to anything. Basically,
I just need to de-blob it and get the vaules.

I tried this:

Set rst = db.OpenRecordset("TableWithBlobField")
lngBlobSize = LenB(rst("BlobField"))
abytBlob = rst("BlobField").GetChunk(0, lngBlobSize)
For Each varItem In abytBlob
Debug.Print varItem
Next

the output of this is a bunch of Bytes, so it appears to be working, but the
data I'm looking for is a bunch of Singles. The VB App that did this before
had a "CopyMemory" function that returned a Single. Something like this:

CopyMemory sngBlobValue, abytBlob(lngBlobOffset), 4

I assume sngBlobValue is the return value, but I don't know what
lngBlobOffset is - unless it's 4.

Any ideas how to replicate this in VBA? How are the bytes in the byte array
converted into singles?
Nov 13 '05 #3
I think this is close to what I'm looking for -

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (lpDest As Any, _
lpSource As Any, ByValcbCopy As Long)

Set rst = db.OpenRecordset("TableWithBlobField")
lngBlobSize = LenB(rst("BlobField"))
abytBlob = rst("BlobField").GetChunk(0, lngBlobSize)
Do While lngBlobOffset < lngBlobSize
CopyMemory sngBlobValue, abytBlob(lngBlobOffset), 4
Debug.Print sngBlobValue
Loop

but apparently I'm not declaring or using CopyMemory correctly - Access
quits pretty quickly when the code reaches the line that calls CopyMemory.
Why is CopyMemory crashing Access? How do I get CopyMemory to return the
values in memory to the single variable?
Nov 13 '05 #4
Typo in the declaration was the issue.

This is better but I'm still not sure I'm getting the right data.

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (lpDest As Any, _
lpSource As Any, ByVal bytlen As Long)

Const cnsChunckSize = 4
Set rst = db.OpenRecordset("TableWithBlobField")
Do While Not rst.EOF
lngBlobOffset = 0
lngBlobSize = LenB(rst!BlobField)
abytBlob = rst!BlobField.GetChunk(0, lngBlobSize)
Do While lngBlobOffset < lngBlobSize
CopyMemory sngBlobValue, abytBlob(lngBlobOffset), 4
Debug.Print sngBlobValue
lngBlobOffset = lngBlobOffset + cnsChunckSize
Loop
rst.MoveNext
Loop

Am I using CopyMemory correctly?
Nov 13 '05 #5
I only use GetChunk when there are bandwidth issues to consider. Just
copy the entire field at once to a Byte array. No CopyMemory nor
GetChunk required.

I do not know if you can directly copy the 4 bytes to a VB Single
variable but I would guess not. If you search on GoogleGroups for
Convert Long to Single" in VB land you will find several examples of
code to coerce the 4 bytes into a Single.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"deko" <de**@hotmail.com> wrote in message
news:bQ******************@newssvr13.news.prodigy.c om...
Typo in the declaration was the issue.

This is better but I'm still not sure I'm getting the right data.

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (lpDest As Any, _
lpSource As Any, ByVal bytlen As Long)

Const cnsChunckSize = 4
Set rst = db.OpenRecordset("TableWithBlobField")
Do While Not rst.EOF
lngBlobOffset = 0
lngBlobSize = LenB(rst!BlobField)
abytBlob = rst!BlobField.GetChunk(0, lngBlobSize)
Do While lngBlobOffset < lngBlobSize
CopyMemory sngBlobValue, abytBlob(lngBlobOffset), 4
Debug.Print sngBlobValue
lngBlobOffset = lngBlobOffset + cnsChunckSize
Loop
rst.MoveNext
Loop

Am I using CopyMemory correctly?


Nov 13 '05 #6
I only use GetChunk when there are bandwidth issues to consider. Just
copy the entire field at once to a Byte array. No CopyMemory nor
GetChunk required.
But isn't each byte in the byte array a pointer to a location in memory?

Are you saying that this is the way to do it:

Set rst = db.OpenRecordset("TableWithBlobField")
Do While Not rst.EOF
abytBlob = rst!BlobField
For Each varItem In abytBlob
Debug.Print varItem
Next
rst.MoveNext
Loop

If I try this:

For Each varItem In abytBlob
CopyMemory sngBlobValue, abytBlob(varItem), 4
Debug.Print sngBlobValue
lngBlobOffset = lngBlobOffset + cnsChunckSize
Next

I get "Subscript out of range" after a few loops.
I do not know if you can directly copy the 4 bytes to a VB Single
variable but I would guess not. If you search on GoogleGroups for
Convert Long to Single" in VB land you will find several examples of
code to coerce the 4 bytes into a Single.


There's no reason I need to use a Single. The goal is to deBlob and dump
out the values to an Excel spreadsheet, so I don't think it matters.
Nov 13 '05 #7
This appears to be correct:

abytBlob = rst!BlobField

But comparing these two loops:

--loop 1--
For Each VarItem in abytBlob
Debug.Print vatItem
Next

[output]
68
67
188
94
68
67
174
93
68
67
....

--loop 2--
Do While Not rst.EOF
abytBlob = rst!BlobField
For i = LBound(abytBlob) To UBound(abytBlob)
CopyMemory sngBlobValue, abytBlob(i), 4
Debug.Print sngBlobValue
i = i + 1
Next
rst.MoveNext
Loop

[output]
196.3302
9.570064E+12
196.3322
1.421259E+14
196.3399
5.847288E+09
196.3112
2.580507E+10
196.3154
7.048431E+14
196.3442
....

The output of the second loop (with CopyMemory) returns vaules (e.g.
196.xxxx) that are consistent with what I'm looking for. But why is every
other value some huge number?
Nov 13 '05 #8
Success!!

Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" (lpDest As Any, _
lpSource As Any, ByVal bytlen As Long)

Const CHUNKSZ = 4
Set rst = db.OpenRecordset("TableWithBlobField")
Do While Not rst.EOF
lngOffset = 0
lngBsize = LenB(rst!BlobField)
ReDim abytB(lngBsize)
abytB = rst!ScanData.GetChunk(0, lngBsize)
Do While lngOffset < lngBsize
CopyMemory sngBval, abytB(lngOffset), 4
Debug.Print sngBval
lngOffset = lngOffset + CHUNKSZ
Loop
rst.MoveNext
Loop

Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Niko Korhonen | last post by:
I'm currently in the process of programming a multimedia tagging library in standard C++. However, I've stumbled across one or two unclear issues while working with the library. First of all, is...
3
by: Randy | last post by:
I have heard that access 2003 has functions for dealing with Long Binary Data. Does anyone know if this is true? Background: I am using 2000 with a table linked to a SQL server. One of the fields...
8
by: Jerry | last post by:
I have an off-the-shelf app that uses an Access database as its backend. One of the tables contains a field with an "OLE Object" datatype. I'm writing some reports against this database, and I...
1
by: stockblaster | last post by:
Hello all.. Is it possible to convert a DataTable (i create the DataTable from a CSV file) into binary data and save it into an sql 2005 table (into binary field). After that I want to have...
8
by: Mark | last post by:
Hello. I am attempting to write binary data from a file to an OLE Object field, and then write the file back out from the database. I am reading and writing the files in binary mode, and using...
0
by: Chris3000 | last post by:
Hi everyone How can I embeded an image to OLE Object field using Long Binary data. and what Long Binary data means and how to use it. does anyone have any ideas on I would to display...
7
Coldfire
by: Coldfire | last post by:
i am having error ....details are ASP.Net application...in which I have a textbox <asp:TextBox ID="Other" TextMode=SingleLine CssClass="serviceBox" Width="250" Height="45" Runat="server"...
0
by: RN | last post by:
Hi everyone, First please let me explain. I am attempting to store pdf files in an MS Access DB (2000) and I have written a subroutine to do this. My code seems to work perfectly (see code...
4
by: Ty | last post by:
I have a SQL server 2000 DB that Ihave copied onto my PC and am using SQL server express 2005 to view. I created a project in VB.net and am reading the data out of the DB using...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.