Data string with bits and words

  • Thread starter Thread starter Carrie
  • Start date Start date
C

Carrie

I have a data string form another program. The data string
has a defined format in chunks of 16 bytes. The 16 bytes
can be 16 individual bits or a 16 byte integer.

I can create a table design with yes/no fields and integer
fields matching my data sequence.

Is there a way to get the data into this table easily?

I imagine to just "look at the data" through my table
definition...
 
Hi,
I'm not entirely sure this will help you but what about if you put
your string into a byte array?

Dim str As String
Dim arrB() As Byte

str = "test this"
arrB = StrConv(str, vbFromUnicode)
 
I dont think so.

My data structure is like
bit1
bit2
....
bit16
integer1
integer2
....
integer36

and I need to access the value of each individual bit and
integer in my program.

If I could define the structure and just "map" it on my
data, it would save me a lot of data administration.

-----Original Message-----
Hi,
I'm not entirely sure this will help you but what about if you put
your string into a byte array?

Dim str As String
Dim arrB() As Byte

str = "test this"
arrB = StrConv(str, vbFromUnicode)

--
HTH
Dan Artuso, Access MVP


"Carrie" <[email protected]> wrote in
message news:[email protected]...
 
The representation of an individual record is not apparent to me. Is it
like this:

record1: bit1bit2bit2...bit16integer1integer2...integer36
record2: bit1bit2bit2...bit16integer1integer2...integer36
....
recordn: bit1bit2bit2...bit16integer1integer2...integer36

And where are you getting the data from, if it is from a binary file and the
record definition is consistent then you can simply create a structure, and
read the records directly into the structure for instance (note this code
was written from my head and is probably not syntactly correct, but it
should point you in the right direction)

Type myRecord
bit1 As Byte
bit2 As Byte
...
bit16 As Byte
int1 As Integer
int2 As Integer
...
int36 As Integer
End Type

Dim fh As Integer
Dim rec As myRecord

fh = FreeFile
Open "PathToYourFile" For Binary AS #fh
Do While Not EOF(#fh)
Input #fh, rec
' Import rec into your table here using what ever method you are
comfortable with
Loop

Close fh
 
Your understanding is correct.

In fact data is communicated through a memory area. One
program writes to the area and my program reads it.

I have tried to create a type like you suggest - but since
my data has individual bits, I kind of miss a "1-bit"
datatype.
 
Sorry I was not concentrating on my bits and bytes so if you change the
structure to

Type myRecord
bits1_8 As Byte
bits9_16 As Byte
int1 As Integer
int2 As Integer
...
int36 As Integer
End Type

You can now use the Hex function to convert the variables bit1_8 and
bits9_16 to interrogate the values. Remebering that a Byte represents 8
Bits and also the hex conversion to binary is shown below. Therefore if the
value of bits1_8 is 255 then the hex represntation will be FF with the
binary shown below:

0 - 0000
1 - 0001
2 - 0010
3 - 0011
4 - 0100
5 - 0101
6 - 0110
7 - 0111
8 - 1000
9 - 1001
A - 1010
B - 1011
C - 1100
D - 1101
E - 1110
F - 1111
 
Thank you for the details.

Going back a little - you write
' Import rec into your table here using what ever method
you are comfortable with

Does that mean a field-by-field transfer of values from my
record to the table? Or is there a more efficient way to
transfer the whole structure?
 
Carrie,

IMO I believe that the fastest way to transfer the data to the database
would be the use of a stored query. For instance
create an insert query "sp_InsertMyData" (I do not know offhand the limits
on the number of parameters but you have 52):

INSERT INTO myData (bit1, bit2, bit3, ... bit16, int1, int2, ... int36)
Values ([@bit1], [@bit2], ..., [@bit16],[@int1],..., [@int36])

Before reading the record loop set up the query def as such:

Dim cmd As DAO.QueryDef
Dim cnt As Integer

Set cmd = CurrentDb.QueryDefs("sp_InsertMyData")

Do
'You read you data here
' determine each bit value in a loop
Dim bitValue as Boolean
For cnt = 1 To 16
' Determine the bit values using an algorithm "GetBitValue"
from the info in my last post
If cnt <= 8 Then
bitValue = GetBitValue(myRecord.bits1_8, cnt)
Else
bitValue = GetBitValue(myRecord.bits9_16, cnt)
End If
cmd.Parameters("@bit" & cnt).Value = bitValue
Loop

' Set all of the integer parameters
cmd.Parameters("@int1").Value = myRecord.int1
...
cmd.Parameters("@int36").Value = myRecord.int1

cmd.Execute ' Save the data
' need an exit condition, not sure how you know when to stop
' reading from memory
Loop ' Read next record
 
OK - if I have to do it for every field, I guess I would
do it like:

dim dbs as database
dim rstas recordset

set dbs = currentdb
set rst = dbs.openrecordset("mytable")

with rst
.addnew
!bit1 = myrec.bit1_8(0) 'or how I get the firts bit
!bit2 = myrec.bit1_8(1)
....
!int36 = myrec.int36
.update
end with

I had just hoped I could insert all values in one
statement relying on data and tabledef to follow the exact
same format.

-----Original Message-----
Carrie,

IMO I believe that the fastest way to transfer the data to the database
would be the use of a stored query. For instance
create an insert query "sp_InsertMyData" (I do not know offhand the limits
on the number of parameters but you have 52):

INSERT INTO myData (bit1, bit2, bit3, ... bit16, int1, int2, ... int36)
Values ([@bit1], [@bit2], ..., [@bit16],[@int1],..., [@int36])

Before reading the record loop set up the query def as such:

Dim cmd As DAO.QueryDef
Dim cnt As Integer

Set cmd = CurrentDb.QueryDefs("sp_InsertMyData")

Do
'You read you data here
' determine each bit value in a loop
Dim bitValue as Boolean
For cnt = 1 To 16
' Determine the bit values using an algorithm "GetBitValue"
from the info in my last post
If cnt <= 8 Then
bitValue = GetBitValue (myRecord.bits1_8, cnt)
Else
bitValue = GetBitValue (myRecord.bits9_16, cnt)
End If
cmd.Parameters("@bit" & cnt).Value = bitValue
Loop

' Set all of the integer parameters
cmd.Parameters("@int1").Value = myRecord.int1
...
cmd.Parameters("@int36").Value = myRecord.int1

cmd.Execute ' Save the data
' need an exit condition, not sure how you know when to stop
' reading from memory
Loop ' Read next record

Thank you for the details.

Going back a little - you write
' Import rec into your table here using what ever method
you are comfortable with

Does that mean a field-by-field transfer of values from my
record to the table? Or is there a more efficient way to
transfer the whole structure?

if
you change the variables
bit1_8 and from
a on
my


.
 
Back
Top