Binary Reader HELP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • james

    Binary Reader HELP

    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



  • alejandro lapeyre

    #2
    Re: Binary Reader HELP

    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" <jjames700ReMoV eMe at earthlink dot net> escribió en el mensaje
    news:ePF7NHQHFH A.2616@tk2msftn gp13.phx.gbl...
    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




    Comment

    • james

      #3
      Re: Binary Reader HELP

      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.S eek(fieldinfo + 2, SeekOrigin.Begi n)' 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




      "alejandro lapeyre" <alejandrolapey re@jotmail.com> wrote in message news:e16QPRQHFH A.2136@TK2MSFTN GP14.phx.gbl...[color=blue]
      > 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" <jjames700ReMoV eMe at earthlink dot net> escribió en el mensaje
      > news:ePF7NHQHFH A.2616@tk2msftn gp13.phx.gbl...
      > 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
      >
      >
      >
      >[/color]


      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Binary Reader HELP

        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

        "james" <jjames700ReMoV eMe at earthlink dot net> wrote in message
        news:ePF7NHQHFH A.2616@tk2msftn gp13.phx.gbl...[color=blue]
        >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
        >
        >
        >
        >[/color]


        Comment

        • alejandro lapeyre

          #5
          Re: Binary Reader HELP

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

          dim m_FieldType as FieldType
          dim m_DecimalDigits as byte
          dim m_SignificantDi gits as byte

          select case b
          case &h10
          m_FieldType = FieldType.Index

          case 1
          m_FieldType = FieldType.Curre ncy
          m_DecimalDigits = 2
          m_SignificantDi gits = ReadNextByte()

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

          "james" <jjames700ReMoV eMe at earthlink dot net> escribió en el mensaje
          news:Ox$ghqQHFH A.3008@TK2MSFTN GP10.phx.gbl...
          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.S eek(fieldinfo + 2, SeekOrigin.Begi n)' 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




          "alejandro lapeyre" <alejandrolapey re@jotmail.com> wrote in message
          news:e16QPRQHFH A.2136@TK2MSFTN GP14.phx.gbl...[color=blue]
          > 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" <jjames700ReMoV eMe at earthlink dot net> escribió en el mensaje
          > news:ePF7NHQHFH A.2616@tk2msftn gp13.phx.gbl...
          > 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
          >
          >
          >
          >[/color]



          Comment

          • james

            #6
            Re: Binary Reader HELP

            Alejandro, thanks for the code sample. Your help is appreciated.
            james

            "alejandro lapeyre" <alejandrolapey re@jotmail.com> wrote in message news:ump4v$QHFH A.3780@TK2MSFTN GP10.phx.gbl...[color=blue]
            > enum FieldType
            > Index = 0
            > Currency = 1
            > '...
            > end enum
            >
            > dim m_FieldType as FieldType
            > dim m_DecimalDigits as byte
            > dim m_SignificantDi gits as byte
            >
            > select case b
            > case &h10
            > m_FieldType = FieldType.Index
            >
            > case 1
            > m_FieldType = FieldType.Curre ncy
            > m_DecimalDigits = 2
            > m_SignificantDi gits = ReadNextByte()
            >
            > case ... ' other field types
            > case else
            > debug.writeline ("i dont know this field type yet")
            > end select
            >
            > "james" <jjames700ReMoV eMe at earthlink dot net> escribió en el mensaje
            > news:Ox$ghqQHFH A.3008@TK2MSFTN GP10.phx.gbl...
            > 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.S eek(fieldinfo + 2, SeekOrigin.Begi n)' 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
            >
            >
            >
            >
            > "alejandro lapeyre" <alejandrolapey re@jotmail.com> wrote in message
            > news:e16QPRQHFH A.2136@TK2MSFTN GP14.phx.gbl...[color=green]
            >> 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" <jjames700ReMoV eMe at earthlink dot net> escribió en el mensaje
            >> news:ePF7NHQHFH A.2616@tk2msftn gp13.phx.gbl...
            >> 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
            >>
            >>
            >>
            >>[/color]
            >
            >
            >[/color]


            Comment

            • james

              #7
              Re: Binary Reader HELP

              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

              "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message news:OTGV19QHFH A.4060@TK2MSFTN GP14.phx.gbl...[color=blue]
              > 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[/color]


              Comment

              Working...