ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Gross Faults/Errors With Put and Get (https://www.excelbanter.com/excel-programming/311262-gross-faults-errors-put-get.html)

David A. Heisaer

Gross Faults/Errors With Put and Get
 
I have been trying to build binary files with contigeous bit patterns in
Excel VBA.

I find the Put statement, Put #1, hstart, lv, where hstart is 1& and lv=-1&
(32 one-bits), followed by Put#1, hstart,lv, where now hstart is 33& and
lv=0&, ends up with a totally screwy series of 0011 bit patterns on the
file.

The Get statement is inconsistent in output, depending where it is in the
compile sequence.

Has any body else observed. this?

David Heiser



Myrna Larson

Gross Faults/Errors With Put and Get
 
The units for the position argument are BYTEs, not BITs. A Long Integer
variable occupies 32 bits, but that is 4 bytes, not 33. Your 2nd PUT statement
should write to byte 5, not byte 33.

If you specified hstart as 33 in the 2nd put statement, you've left a gap of
28 bytes in the file. VB/VBA does not overwrite the skipped bytes. What you
see in those 28 bytes is whatever was on the disk before you opened the file
and allocated the disk space for it.

I have never found any problems with the GET statement. Are you confusing bits
and bytes here, too?

The following code creates a file which a hex viewer displays as

FF FF FF FF 01 00 00 00

Sub Test()
Dim LV As Long
Open "TestFile.BIN" For Binary As #1
LV = -1
Put #1, 1, LV
LV = 1
Put #1, , LV
Close #1
End Sub


On Thu, 23 Sep 2004 16:21:59 -0700, "David A. Heisaer"
wrote:

I have been trying to build binary files with contigeous bit patterns in
Excel VBA.

I find the Put statement, Put #1, hstart, lv, where hstart is 1& and lv=-1&
(32 one-bits), followed by Put#1, hstart,lv, where now hstart is 33& and
lv=0&, ends up with a totally screwy series of 0011 bit patterns on the
file.

The Get statement is inconsistent in output, depending where it is in the
compile sequence.

Has any body else observed. this?

David Heiser




All times are GMT +1. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com