Exporting unicode characters to a file (at this point I dont carewhat type of file)

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

    Exporting unicode characters to a file (at this point I dont carewhat type of file)

    We purchased som software for encoding a barcode. We want to
    automate the process of converting a number to a readable barcode.

    However, I am having a few issues.

    The file that the barcode needs to be appended to is dbf file type,
    I wrote a dbf writer so adding data on the fly is not a problem, the
    problem is
    trying to get the correct encoding. The barcode utility that we
    purchased
    works fine. However, when I write the values of the barcode to a dbf,
    txt, csv, the
    values are not identical. Here is the data comparision.

    Original value of the field that is being converted to a barcode:

    41864-00001~



    the conversion value is: (value generated by the barcode utility that
    we purchased):

    ÍIvÈ4-0ÇÂ!È~}Î <--- note this is the value I need to be
    exported for barcode scanning.


    I use a binary writer to export the values to a dbf file and when i
    open the dbf to view it, I get the following values:

    'using System.Text.ASC IIEncoding.UTF8 .GetBytes(_impo rtCode)

    ÍIvÈ4-0ÇÂ!


    'using System.Text.ASC IIEncoding.UTF7 .GetBytes(_impo rtCode)
    +AM0-Iv+AMg-4-




    I've also tried writing it to text file, but still the same issue. We
    currently are using a vba module to export the file however
    this is not done using automation. Any advice?
  • Herfried K. Wagner [MVP]

    #2
    Re: Exporting unicode characters to a file (at this point I dont care what type of file)

    "JimmyKoolPantz " <kohl.mike@gmai l.comschrieb:
    >The file that the barcode needs to be appended to is dbf file type,
    >I wrote a dbf writer so adding data on the fly is not a problem, the
    >problem is
    >trying to get the correct encoding. The barcode utility that we
    >purchased
    >works fine. However, when I write the values of the barcode to a dbf,
    >txt, csv, the
    >values are not identical. Here is the data comparision.
    >
    >Original value of the field that is being converted to a barcode:
    >
    >41864-00001~
    >
    >the conversion value is: (value generated by the barcode utility that
    >we purchased):
    >
    >ÍIvÈ4-0ÇÂ!È~}Î <--- note this is the value I need to be
    >exported for barcode scanning.
    >
    >I use a binary writer to export the values to a dbf file and when i
    >open the dbf to view it, I get the following values:
    Post the code you use to read and write the values to the file.

    Note that .NET strings are always UTF-16 strings, and reading text with a
    certain encoding will only guaranteed to work if it has been written using
    the same encoding.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • JimmyKoolPantz

      #3
      Re: Exporting unicode characters to a file (at this point I dont carewhat type of file)

      On Jul 22, 12:53 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
      h...@gmx.atwrot e:
      "JimmyKoolPantz " <kohl.m...@gmai l.comschrieb:
      >
      >
      >
      >
      >
      The file that the barcode needs to be appended to is dbf file type,
      I wrote a dbf writer so adding data on the fly is not a problem, the
      problem is
      trying to get the correct encoding.  The barcode utility that we
      purchased
      works fine.  However, when I write the values of the barcode to a dbf,
      txt, csv, the
      values are not identical. Here is the data comparision.
      >
      Original value of the field that is being converted to a barcode:
      >
      41864-00001~
      >
      the conversion value is: (value generated by the barcode utility that
      we purchased):
      >
      ÍIvÈ4-0ÇÂ!È~}Î           <--- note this is the value I need to be
      exported for barcode scanning.
      >
      I use a binary writer to export the values to a dbf file and when i
      open the dbf to view it, I get the following values:
      >
      Post the code you use to read and write the values to the file.
      >
      Note that .NET strings are always UTF-16 strings, and reading text with a
      certain encoding will only guaranteed to work if it has been written using
      the same encoding.
      >
      --
       M S   Herfried K. Wagner
      M V P  <URL:http://dotnet.mvps.org/>
       V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>- Hide quoted text -
      >
      - Show quoted text -
      I've been trying to figure this out all day. I've tried exporting the
      file as a dbf, CSV, and Text and still nothing seems to be working.
      One thing I did figure out(I think) is. when creating a textfile
      using a filestream in .net. The default encoding is UTF-8. So when I
      converted the text file to a .csv file and opened it up in excel,
      excel recognized the BOM as a non unicode file, so that is why the
      characters were not being displayed correctly. If I save the file
      with the encoding type of unicode then the unicode characters would
      display correctly. However, each line would be displayed into one
      cell. Which was not good.

      Another thing I tried was changing the encoding when declaring the
      file stream and then create a tab text file which looked good on my
      side, however, this did not look good at the printer.
      Now im back trying to insert it into a dbf file. Here is some of the
      code I am working with now.

      I left most the code out, however what im basically doing is opening
      a dbf file, filtering thru each record, and if the field name is
      IMPORTCODE I take the value in that field and then encode the value
      using a 3rd party dll. No problem with the dlll. IF the field name is
      SCANCODE then I write the values out to the dbf file.

      example in .net the _scancode = "ÍIvÈ4-0ÇÂ!È~}Î "
      when i open the dbf file using excel I get the value = "═Iv╚4-0╟┬!╚~}"
      if I open the file in ultra Edit I get the value = ÍIvÈ4-0ÇÂ!È~}

      However, when the printing software opens the file they get the same
      thing I see in excel which looks like a corrupted barcode.


      Private fs_Reader As FileStream
      Dim br As BinaryReader = Nothing
      Dim bw As BinaryWriter = Nothing

      fs_Reader = New FileStream(_fil epath, FileMode.Open)
      br = New BinaryReader(fs _Reader)
      bw = New BinaryWriter(fs _Reader, System.Text.Enc oding.Unicode)

      For inum As Integer = 0 To _recordCount - 1
      If (al(int) = "IMPORTCODE ") Then
      _importCode = GetImportCode(t emp)
      _scanCode = System.Text.Enc oding.Unicode.G etBytes(_import Code)



      ElseIf (al(int) = "SCANCODE") Then
      Mark = fs_Reader.Posit ion - Field_Length
      bw.Seek(Mark, SeekOrigin.Begi n)
      bw.Write(_scanC ode, 0, 13)
      end if
      Next









      Comment

      Working...