Binary Reader HELP

J

james

I will try to make this short and to the point.
I am reading values from a file using a Binary Reader.
At a particular address I can get a value of , Hex 10 or Hex 01 . (varies can be 30, 20, 02,03 etc.)
I need to keep those values as shown..........10 or 01.
And then split the value........ for instance the 10 becomes 1 or 0. (extract either the 1 or the 0 and display it)
Or in the case of the 01,,,,,,,,,,,0 or 1.( extract either the 0 or the 1 and display it)

I have no problem reading the address that contains the values but, I cannot find a way to retain the actual
numbers ( 10 or 01 ) and then split them and display them in a textbox or listbox.
Any ideas would be greatly appreciated.
james
 
A

alejandro lapeyre

Public Function ByteToHex(ByVal b As Byte) As String
Return Hex(&H100 + b).Substring(1)
End Function

This will allways return a string of lenght = 2

regards
Alejandro Lapeyre
"james" <jjames700ReMoVeMe at earthlink dot net> escribió en el mensaje
I will try to make this short and to the point.
I am reading values from a file using a Binary Reader.
At a particular address I can get a value of , Hex 10 or Hex 01 . (varies
can be 30, 20, 02,03 etc.)
I need to keep those values as shown..........10 or 01.
And then split the value........ for instance the 10 becomes 1 or 0.
(extract either the 1 or the 0 and display it)
Or in the case of the 01,,,,,,,,,,,0 or 1.( extract either the 0 or the 1
and display it)

I have no problem reading the address that contains the values but, I cannot
find a way to retain the actual
numbers ( 10 or 01 ) and then split them and display them in a textbox or
listbox.
Any ideas would be greatly appreciated.
james
 
J

james

Alejandro, thanks for the function. Here is what I have going and gets the same results as your function:

dim a as Integer
br.BaseStream.Seek(fieldinfo + 2, SeekOrigin.Begin)' br is a Binary Reader and Seeks fieldinfo (a Hex Address) + 2 positions
'over and then br.ReadByte() reads the byte at that location

a = br.ReadByte() 'reads 1 Byte for Index

a = Hex(a)

ListBox1.Items.Add(" INDEX#: " + (a).ToString())

What I need to have happen is, if the returned value is a 10 , I need only the 1 to be added to the listbox.
and drop the 0. (also this would tell me that the Value is for an Index only........in this case)
If the returned value is 01 I need the 1 (but, from the Right Side of the 01, because the 1 from the Right Side of the 01
would tell me that I have a Currency value and the 1 means that the Currency value has TWO places to the Right of a Decimal
point. (the next value I read with Binary Reader tells me how many numbers to the LEFT of the Decimal are allowed in the field.
I am reading an old (DOS based) Database file header, and getting Field Types and Sizes and that is why I need to split the , 10
or 01 so that I know what type of Field ( regular Numeric or Currency) it is.
james
 
J

Jay B. Harlow [MVP - Outlook]

James,
In addition to the other comments.

It sounds like you want the low nybble or high nybble of a byte.

In VS.NET 2003 you can use the Shift operator, the And operator & the Or
operator to extract or combine each half of a byte.

Dim value As Byte = &H13
Dim high As Byte = HighByte(value)
Dim low As Byte = LowByte(value)

Debug.WriteLine(value.ToString("X2"), "value")
Debug.WriteLine(high.ToString("X1"), "high")
Debug.WriteLine(low.ToString("X1"), "low")

Public Shared Function LowByte(ByVal value As Byte) As Byte
Const mask As Byte = &HF
Return value And mask
End Function

Public Shared Function HighByte(ByVal value As Byte) As Byte
Const mask As Byte = &HF
Return (value >> 4) And mask
End Function

In VS.NET 2003 & later, >> is the right shift operator, while << is the left
shift operator.

Hope this helps
Jay
 
A

alejandro lapeyre

enum FieldType
Index = 0
Currency = 1
'...
end enum

dim m_FieldType as FieldType
dim m_DecimalDigits as byte
dim m_SignificantDigits as byte

select case b
case &h10
m_FieldType = FieldType.Index

case 1
m_FieldType = FieldType.Currency
m_DecimalDigits = 2
m_SignificantDigits = ReadNextByte()

case ... ' other field types
case else
debug.writeline("i dont know this field type yet")
end select

"james" <jjames700ReMoVeMe at earthlink dot net> escribió en el mensaje
Alejandro, thanks for the function. Here is what I have going and gets the
same results as your function:

dim a as Integer
br.BaseStream.Seek(fieldinfo + 2, SeekOrigin.Begin)' br is a Binary Reader
and Seeks fieldinfo (a Hex Address) + 2 positions
'over and then br.ReadByte() reads the byte at that location

a = br.ReadByte() 'reads 1 Byte for Index

a = Hex(a)

ListBox1.Items.Add(" INDEX#: " + (a).ToString())

What I need to have happen is, if the returned value is a 10 , I need only
the 1 to be added to the listbox.
and drop the 0. (also this would tell me that the Value is for an Index
only........in this case)
If the returned value is 01 I need the 1 (but, from the Right Side of the
01, because the 1 from the Right Side of the 01
would tell me that I have a Currency value and the 1 means that the Currency
value has TWO places to the Right of a Decimal
point. (the next value I read with Binary Reader tells me how many numbers
to the LEFT of the Decimal are allowed in the field.
I am reading an old (DOS based) Database file header, and getting Field
Types and Sizes and that is why I need to split the , 10
or 01 so that I know what type of Field ( regular Numeric or Currency) it
is.
james
 
J

james

Jay, again, thank you for your help and code sample(s). Using what you have posted, I am getting this thing whipped. I really
appreciate your help.
I had one table that contained a field that was supposed to be a Currency field, that fooled your code.
That is, until I noticed that the table contained no data and was never referenced in the old application or by any of the other
tables. I guess the original programmer never bothered to remove it from his application or intended to use it one day. But, in
all the other tables that I know are used, and contain Currency fields, using your code (after referencing it correctly
:),,,,,,,,,,,,my conversion utility correctly identifies all the Currency Fields in tables.
Now, to go and start retreiving the actual data itself and building the Database (Access) with ADOX using the Field data from
the import utility. (fun, fun, fun!)
james
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top