I am trying to optimize my code for reading from an image column in an ADO
recordset using GetChunk. With the below code an 'Out of Memory' error is
sometimes raised if the value in the column is too large.
<...>
lSize = rsLayout!cross_layout.ActualSize
If lSize > 0 Then
rsLayout!cross_layout.GetChunk lSize
mvarLayout = rsLayout!cross_layout
End If
<...>
I changed the code to
<...>
lSize = rsLayout!cross_layout.ActualSize
If lSize > 0 Then
WriteFromColumnToVariant mvarLayout, rsLayout!cross_layout, lSize
End If
Public Sub WriteFromColumnToVariant(vVariant As Variant, fld As ADODB.Field,
_
ByVal FieldSize As Long)
Dim vData As Variant
Dim lCharsRead As Long
Dim lChunkSize As Long
lChunkSize = 1024
Do While FieldSize <> lCharsRead
If FieldSize - lCharsRead < lChunkSize Then
If FieldSize - lChunkSize < 0 Then
vData = fld.GetChunk(FieldSize)
Else
vData = fld.GetChunk(FieldSize - lChunkSize)
End If
lCharsRead = FieldSize
Else
vData = fld.GetChunk(lChunkSize)
lCharsRead = lCharsRead + lChunkSize
End If
If Not IsEmpty(vVariant) Then
vVariant = vVariant & vData
Else
vVariant = vData
End If
Loop
End Sub
<...>
And now the data contained in mvarLayout is not accurate. Did I do
something wrong?
Thanks for any help.
Dan
Paul Clement - 26 Jun 2006 15:28 GMT
¤ I am trying to optimize my code for reading from an image column in an ADO
¤ recordset using GetChunk. With the below code an 'Out of Memory' error is
¤ sometimes raised if the value in the column is too large.
¤
¤ <...>
¤
¤ lSize = rsLayout!cross_layout.ActualSize
¤ If lSize > 0 Then
¤ rsLayout!cross_layout.GetChunk lSize
¤ mvarLayout = rsLayout!cross_layout
¤ End If
¤
¤ <...>
¤
¤ I changed the code to
¤
¤ <...>
¤
¤ lSize = rsLayout!cross_layout.ActualSize
¤ If lSize > 0 Then
¤ WriteFromColumnToVariant mvarLayout, rsLayout!cross_layout, lSize
¤ End If
¤
¤ Public Sub WriteFromColumnToVariant(vVariant As Variant, fld As ADODB.Field,
¤ _
¤ ByVal FieldSize As Long)
¤
¤ Dim vData As Variant
¤ Dim lCharsRead As Long
¤ Dim lChunkSize As Long
¤
¤ lChunkSize = 1024
¤
¤ Do While FieldSize <> lCharsRead
¤ If FieldSize - lCharsRead < lChunkSize Then
¤ If FieldSize - lChunkSize < 0 Then
¤ vData = fld.GetChunk(FieldSize)
¤ Else
¤ vData = fld.GetChunk(FieldSize - lChunkSize)
¤ End If
¤ lCharsRead = FieldSize
¤ Else
¤ vData = fld.GetChunk(lChunkSize)
¤ lCharsRead = lCharsRead + lChunkSize
¤ End If
¤ If Not IsEmpty(vVariant) Then
¤ vVariant = vVariant & vData
¤ Else
¤ vVariant = vData
¤ End If
¤ Loop
¤
¤ End Sub
¤
¤ <...>
¤
¤ And now the data contained in mvarLayout is not accurate. Did I do
¤ something wrong?
Could you indicate what isn't accurate? What sort of data is this?
Paul
~~~~
Microsoft MVP (Visual Basic)
Dan Reber - 26 Jun 2006 15:45 GMT
It is a proprietary layout file for one of the ActiveX controls that I use
so I am not sure what is missing. The error that I get is 'Type Mismatch'
at 'oStream.Write (mvarLayout)'
Set oStream = New ADODB.Stream
oStream.type = adTypeBinary
oStream.Open
oStream.Write (mvarLayout)
Thanks for your help.
Dan
Dan Reber - 26 Jun 2006 15:51 GMT
Wrong error description, the correct one at 'oStream.Write (mvarLayout)' is
'Arguments are of the wrong type, are out of acceptable range, or are in
conflict with one another.'
Thanks
Dan
> It is a proprietary layout file for one of the ActiveX controls that I use
> so I am not sure what is missing. The error that I get is 'Type Mismatch'
[quoted text clipped - 8 lines]
>
> Dan
Paul Clement - 26 Jun 2006 19:15 GMT
¤ Wrong error description, the correct one at 'oStream.Write (mvarLayout)' is
¤
¤ 'Arguments are of the wrong type, are out of acceptable range, or are in
¤ conflict with one another.'
What if you try the following instead:
oStream.Write rsLayout!cross_layout
Paul
~~~~
Microsoft MVP (Visual Basic)
Dan Reber - 26 Jun 2006 19:42 GMT
Will 'oStream.Write rsLayout!cross_layout' get chucks of data instead of
trying to get the whole value?
Thanks
Dan
> ¤ Wrong error description, the correct one at 'oStream.Write (mvarLayout)'
> is
[quoted text clipped - 9 lines]
> ~~~~
> Microsoft MVP (Visual Basic)
Paul Clement - 27 Jun 2006 15:00 GMT
¤ Will 'oStream.Write rsLayout!cross_layout' get chucks of data instead of
¤ trying to get the whole value?
¤
It should try to fetch the complete file. I don't know if you will get the "out of memory" error but
it won't hurt to try it.
Paul
~~~~
Microsoft MVP (Visual Basic)