By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,255 Members | 2,640 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,255 IT Pros & Developers. It's quick & easy.

Array of bytes

P: n/a
Working with a 3rd party API which calls for an array of bytes to upload
data from a file to a data stream.

========================================
'CODE THAT WORKS
Const bLen = 4096
Dim bData(bLen) As Byte

Open frm.DocPath For Binary Access Read Lock Read As #1
For i = 1 To (LOF(1) \ bLen)
Get #1, , bData
objPutStream.Write bData, bLen + 1
Next i
Close #1
========================================

I want to vary the size of the Const, from a range of 256 to 16384,
depending on the source file size. But Access complains if I use anything
but a Const in the Dim statement.

Any ideas?


Feb 21 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Tue, 20 Feb 2007 23:29:18 -0500, "Builder" <no****@builder.com>
wrote:

Use Redim:
Dim bData() As Byte
Redim bData(intWhatever)

Note that technically you have to Erase this array after use.

-Tom.

>Working with a 3rd party API which calls for an array of bytes to upload
data from a file to a data stream.

========================================
'CODE THAT WORKS
Const bLen = 4096
Dim bData(bLen) As Byte

Open frm.DocPath For Binary Access Read Lock Read As #1
For i = 1 To (LOF(1) \ bLen)
Get #1, , bData
objPutStream.Write bData, bLen + 1
Next i
Close #1
========================================

I want to vary the size of the Const, from a range of 256 to 16384,
depending on the source file size. But Access complains if I use anything
but a Const in the Dim statement.

Any ideas?


Feb 21 '07 #2

P: n/a
Tom van Stiphout wrote:
On Tue, 20 Feb 2007 23:29:18 -0500, "Builder" <no****@builder.com>
wrote:

Use Redim:
Dim bData() As Byte
Redim bData(intWhatever)

Note that technically you have to Erase this array after use.
I tried ReDim earlier, but it wouldn't work, and I think it's because I
probably did this:

Dim bData(4096) As Byte
ReDim bData(8192)
Looks promising - will try tomorrow onsite. Thanks for the quick response.


-Tom.

>Working with a 3rd party API which calls for an array of bytes to
upload data from a file to a data stream.

========================================
'CODE THAT WORKS
Const bLen = 4096
Dim bData(bLen) As Byte

Open frm.DocPath For Binary Access Read Lock Read As #1
For i = 1 To (LOF(1) \ bLen)
Get #1, , bData
objPutStream.Write bData, bLen + 1
Next i
Close #1
========================================

I want to vary the size of the Const, from a range of 256 to 16384,
depending on the source file size. But Access complains if I use
anything but a Const in the Dim statement.

Any ideas?

Feb 21 '07 #3

P: n/a
On Feb 21, 12:02 am, "Builder" <nos...@builder.comwrote:
Tom van Stiphout wrote:
On Tue, 20 Feb 2007 23:29:18 -0500, "Builder" <nos...@builder.com>
wrote:
Use Redim:
Dim bData() As Byte
Redim bData(intWhatever)
Note that technically you have to Erase this array after use.

I tried ReDim earlier, but it wouldn't work, and I think it's because I
probably did this:

Dim bData(4096) As Byte
ReDim bData(8192)
TTBOMK it is unnecessary to use a dynamic byte array as the repository
for a string.

Dim b() As Byte
b = StrConv("Builder", vbFromUnicode)
Debug.Print UBound(b) 'shows 6

There is no need for Redim, or Erase.
Feb 21 '07 #4

P: n/a
Lyle Fairfield wrote:
On Feb 21, 12:02 am, "Builder" <nos...@builder.comwrote:
>Tom van Stiphout wrote:
>>On Tue, 20 Feb 2007 23:29:18 -0500, "Builder" <nos...@builder.com>
wrote:
>>Use Redim:
Dim bData() As Byte
Redim bData(intWhatever)
>>Note that technically you have to Erase this array after use.

I tried ReDim earlier, but it wouldn't work, and I think it's
because I probably did this:

Dim bData(4096) As Byte
ReDim bData(8192)

TTBOMK it is unnecessary to use a dynamic byte array as the repository
for a string.

It's for reading (and writing) binary data.

Const bLen = 4096
Dim bData(bLen) As Byte

Open file For Binary Access Read Lock Read As #1
For i = 1 To (LOF(1) \ bLen)
Get #1, , bData
objPutStream.Write bData, bLen + 1
Next i
Close #1

Dim b() As Byte
b = StrConv("Builder", vbFromUnicode)
Debug.Print UBound(b) 'shows 6

There is no need for Redim, or Erase.

Feb 21 '07 #5

P: n/a
"Builder" <no****@builder.comwrote in news:tyXCh.37982$19.34914
@bignews3.bellsouth.net:
It's for reading (and writing) binary data.
All data are strings.
Public Function GetBinaryStream(ByVal vFullPath$)
Dim FileNumber&
Dim Stream() As Byte

On Error GoTo GetBinaryStreamErr

FileNumber = FreeFile()
Open vFullPath For Binary As #FileNumber
Stream = StrConv(String(LOF(FileNumber), vbNullChar), vbFromUnicode)
Get #FileNumber, , Stream
Close #FileNumber

GetBinaryStream = Stream

GetBinaryStreamExit:
Close
Exit Function

GetBinaryStreamErr:
MsgBox Err.Description, vbCritical, "Error: " & Err.Number
Resume GetBinaryStreamExit
End Function

Sub temp()
Dim FileName$
FileName = SysCmd(acSysCmdAccessDir) & "msaccess.exe"
Debug.Print FileName
Debug.Print FileLen(FileName)
Debug.Print UBound(GetBinaryStream(FileName)) + 1
End Sub
Feb 21 '07 #6

P: n/a
Lyle Fairfield wrote:
"Builder" <no****@builder.comwrote in news:tyXCh.37982$19.34914
@bignews3.bellsouth.net:
>It's for reading (and writing) binary data.

All data are strings.
Public Function GetBinaryStream(ByVal vFullPath$)
Dim FileNumber&
Dim Stream() As Byte

On Error GoTo GetBinaryStreamErr

FileNumber = FreeFile()
Open vFullPath For Binary As #FileNumber
Stream = StrConv(String(LOF(FileNumber), vbNullChar),
vbFromUnicode)
Get #FileNumber, , Stream
I was exploring something like this yesterday: I wanted to put the entire
file contents into the array in one pass. What is the Stream statement
doing?


Close #FileNumber

GetBinaryStream = Stream

GetBinaryStreamExit:
Close
Exit Function

GetBinaryStreamErr:
MsgBox Err.Description, vbCritical, "Error: " & Err.Number
Resume GetBinaryStreamExit
End Function

Sub temp()
Dim FileName$
FileName = SysCmd(acSysCmdAccessDir) & "msaccess.exe"
Debug.Print FileName
Debug.Print FileLen(FileName)
Debug.Print UBound(GetBinaryStream(FileName)) + 1
End Sub

Feb 21 '07 #7

P: n/a
On Feb 21, 9:14 am, "Builder" <nos...@builder.comwrote:
I was exploring something like this yesterday: I wanted to put the entire
file contents into the array in one pass. What is the Stream statement
doing?
It's populating the byte array with the appropriate number of bytes.

Feb 21 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.