473,881 Members | 1,679 Online
Bytes | Software Development & Data Engineering Community
+ 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 11250
*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.olePict ure.Value) / 4
ReDim a(0 To lTemp)

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

--

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.c om> wrote in message
news:AC******** **********@news svr13.news.prod igy.com...
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.olePict ure.Value) / 4
ReDim a(0 To lTemp)

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


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.OpenRecordse t("TableWithBlo bField")
lngBlobSize = LenB(rst("BlobF ield"))
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(lngBlo bOffset), 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 "RtlMoveMem ory" (lpDest As Any, _
lpSource As Any, ByValcbCopy As Long)

Set rst = db.OpenRecordse t("TableWithBlo bField")
lngBlobSize = LenB(rst("BlobF ield"))
abytBlob = rst("BlobField" ).GetChunk(0, lngBlobSize)
Do While lngBlobOffset < lngBlobSize
CopyMemory sngBlobValue, abytBlob(lngBlo bOffset), 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 "RtlMoveMem ory" (lpDest As Any, _
lpSource As Any, ByVal bytlen As Long)

Const cnsChunckSize = 4
Set rst = db.OpenRecordse t("TableWithBlo bField")
Do While Not rst.EOF
lngBlobOffset = 0
lngBlobSize = LenB(rst!BlobFi eld)
abytBlob = rst!BlobField.G etChunk(0, lngBlobSize)
Do While lngBlobOffset < lngBlobSize
CopyMemory sngBlobValue, abytBlob(lngBlo bOffset), 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.c om> wrote in message
news:bQ******** **********@news svr13.news.prod igy.com...
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 "RtlMoveMem ory" (lpDest As Any, _
lpSource As Any, ByVal bytlen As Long)

Const cnsChunckSize = 4
Set rst = db.OpenRecordse t("TableWithBlo bField")
Do While Not rst.EOF
lngBlobOffset = 0
lngBlobSize = LenB(rst!BlobFi eld)
abytBlob = rst!BlobField.G etChunk(0, lngBlobSize)
Do While lngBlobOffset < lngBlobSize
CopyMemory sngBlobValue, abytBlob(lngBlo bOffset), 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.OpenRecordse t("TableWithBlo bField")
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(varIte m), 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 "RtlMoveMem ory" (lpDest As Any, _
lpSource As Any, ByVal bytlen As Long)

Const CHUNKSZ = 4
Set rst = db.OpenRecordse t("TableWithBlo bField")
Do While Not rst.EOF
lngOffset = 0
lngBsize = LenB(rst!BlobFi eld)
ReDim abytB(lngBsize)
abytB = rst!ScanData.Ge tChunk(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
8787
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 it safe to store binary data in std::string? This question rose from my implementation with APEv2 tags. An APEv2 tag's field value can contain either UTF encoded text or binary data. I've decided to use std::string to represent the field value....
3
7223
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 is of type OLE Object. This table is populated from a website where excell spreadsheets are uploaded. But in the linked Access table instead of saying Excell spreadsheet in that field it says Long Binary Data, which can not be opened. My users on...
8
25424
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 believe this field contains data I need. When I view the table in datasheet view, all I can see in this field is the string "Long binary data". So, I've got the problem of needing to extract data from this field, but I don't know what format...
1
2052
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 the ability to add a row to the beginning of the to the binary data.. And ability to remove a row..
8
8937
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 GetChunk and AppendChunk to read and write binary data from the OLE Object field. I am using VBA and DAO for this experiment. The OLE Object field is being used to store Long Binary data.
0
1626
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 images in my asp page. I am trying to insert the images in to MS Access using long binary data. so How can I insert a long binary data to ole object field. Thanx
7
17727
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" MaxLength="1000" /></asp:TextBox> and this textbox is in a <asp:Repeater > which has the count of 35. The textbox value is stored in the SQL DB And the field data-type in the SQL DB is VARCHAR(1000)
0
1525
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 below). Imports System.IO Imports System.Data.OleDb
4
2564
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 System.Data.SqlClient Here is the problem. I am redaing the table fields into variables. All are fine except one. The table has one field that is a binary data type. This field holds
0
9931
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11105
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10827
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9556
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7954
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7113
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5781
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4599
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 we have to send another system
2
4198
muto222
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.