Trying to read a record that contains binary and Ascii data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JimN1
    New Member
    • Dec 2006
    • 21

    Trying to read a record that contains binary and Ascii data

    I have a file the contains a binary field in it. I am not interested in the binary field. However, I am using Lineinput as my reading method. It interprets the binary data as a carriage return/linefeed and this blows up my pgm.
    Is there another type of read that I can use? For ex: ReadText or StreamReader? If yes, can you provide an example in Visual Basic?

    Thanks,
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by JimN1
    I have a file the contains a binary field in it. I am not interested in the binary field. However, I am using Lineinput as my reading method. It interprets the binary data as a carriage return/linefeed and this blows up my pgm.
    Is there another type of read that I can use? For ex: ReadText or StreamReader? If yes, can you provide an example in Visual Basic?
    Are the lines of a fixed length? If so you can use Binary or Random mode, and just grab each line as a single chunk.

    If not, then perhaps the simplest (though far from the most efficient) way is to open it in Binary mode and Get one byte at a time.

    But whatever method you use to access the record, the important thing is to know how to differentiate between the end of a record, and something embedded in the data which looks like the end of the record. How do you plan to do that? For example, is the "binary field" a set length?

    Comment

    • JimN1
      New Member
      • Dec 2006
      • 21

      #3
      Originally posted by Killer42
      Are the lines of a fixed length? If so you can use Binary or Random mode, and just grab each line as a single chunk.

      If not, then perhaps the simplest (though far from the most efficient) way is to open it in Binary mode and Get one byte at a time.

      But whatever method you use to access the record, the important thing is to know how to differentiate between the end of a record, and something embedded in the data which looks like the end of the record. How do you plan to do that? For example, is the "binary field" a set length?


      The data is fixed length. It looks like:
      1001CPCP 200610017015%PH YS ÿÿÿ‹061011T0316 00500RO
      1001CPCP 200610017015%PH YS ÿÿÿ061011T0316 00600RO
      1001CPCP 200610017015%PH YS ÿÿÿ
      061011T03160070 0RO
      1001CPCP 200610017015%PH YS ÿÿöí061012T0257 40100RO
      1001CPCP 200610017015%PH YS ÿÿþ]061012T02574030 0RO

      The data I am interested starts in position 40. Note the 3rd line has broken due to the binary data being interpreted as ctrl/lf.

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        You can read each line or record into an array using random or binary access and then translate the characters at position 40 to whatever, probably 47 into another variable. If this is too much of a stretch for you I will put some code together that should work

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by JimN1
          The data is fixed length. It looks like:
          ...
          The data I am interested starts in position 40. Note the 3rd line has broken due to the binary data being interpreted as ctrl/lf.
          If they're fixed length, that's easy. Just open in Binary mode, set a buffer (string variable or byte array) to the right size making sure you allow room for the end of record delimiter character(s), then Get each record into that buffer and throw away the unwanted part - for example by Mid( ) function.

          Comment

          • JimN1
            New Member
            • Dec 2006
            • 21

            #6
            Originally posted by Killer42
            If they're fixed length, that's easy. Just open in Binary mode, set a buffer (string variable or byte array) to the right size making sure you allow room for the end of record delimiter character(s), then Get each record into that buffer and throw away the unwanted part - for example by Mid( ) function.

            Do you have an example of code doing this?

            Comment

            • Killer42
              Recognized Expert Expert
              • Oct 2006
              • 8429

              #7
              Originally posted by JimN1
              Do you have an example of code doing this?
              I'd suggest you look up the Open and Get statements, and the Mid function, and have a play with them. You'll find it all much easier if you develop an understanding of how to use them. The doco includes examples.

              Comment

              Working...