E
eselk
I hardly ever use VBA, so I'm not sure on the syntax, and I'm sure
everything else I'm doing is wrong also (but it works, so I'm not
worried about that for now).
I use Open to open a binary file. I then use Input to read in 1024
bytes, which is one record. I then parse through the data and set
field values for a table in my Access database. I do something like
this:
buffer = Input 1, 1024
offset = 0
for x = 0 to RecordSet.Fields(x).Count - 1
field_size = RecordSet.Fields(x).FieldSize
RecordSet.Fields(x).Value = mid(buffer,offset,field_size)
offset = offset + field_size
next x
It works fine for Text fields, but I'm also trying to get it to work
for "Large Integer" and "Integer" fields. But I'm not sure on the
correct syntax. This is what I tried, but it didn't work:
dim l as long
l = asc(mid(buffer,1,1)) * 256 * 256 * 256
l = l + (asc(mid(buffer,2,1)) * 256 * 256)
l = l + (asc(mid(buffer,3,1)) * 256)
l = l + asc(mid(buffer,4,1))
Anyway, when all of you VBA coders stop laughing and pick yourself up
off the floor (after seeing my awful code), can you please tell me the
correct syntax.
"buffer" is a string returned by Input, which contains a C-style long
value which is stored as 4 bytes, the first byte being the most
signifigant. If I was doing this in C I'd have no problems, since I
could just do this:
long l;
memcpy(&l,buffer,sizeof(l));
What I'm trying to do with all of this is write some code that will
read in a proprietary data format and dump the data into my Access
table. I'd rather do it this way than convert to DBF or ASCII and then
import.
everything else I'm doing is wrong also (but it works, so I'm not
worried about that for now).
I use Open to open a binary file. I then use Input to read in 1024
bytes, which is one record. I then parse through the data and set
field values for a table in my Access database. I do something like
this:
buffer = Input 1, 1024
offset = 0
for x = 0 to RecordSet.Fields(x).Count - 1
field_size = RecordSet.Fields(x).FieldSize
RecordSet.Fields(x).Value = mid(buffer,offset,field_size)
offset = offset + field_size
next x
It works fine for Text fields, but I'm also trying to get it to work
for "Large Integer" and "Integer" fields. But I'm not sure on the
correct syntax. This is what I tried, but it didn't work:
dim l as long
l = asc(mid(buffer,1,1)) * 256 * 256 * 256
l = l + (asc(mid(buffer,2,1)) * 256 * 256)
l = l + (asc(mid(buffer,3,1)) * 256)
l = l + asc(mid(buffer,4,1))
Anyway, when all of you VBA coders stop laughing and pick yourself up
off the floor (after seeing my awful code), can you please tell me the
correct syntax.
"buffer" is a string returned by Input, which contains a C-style long
value which is stored as 4 bytes, the first byte being the most
signifigant. If I was doing this in C I'd have no problems, since I
could just do this:
long l;
memcpy(&l,buffer,sizeof(l));
What I'm trying to do with all of this is write some code that will
read in a proprietary data format and dump the data into my Access
table. I'd rather do it this way than convert to DBF or ASCII and then
import.