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

J

JimmyKoolPantz

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.ASCIIEncoding.UTF8.GetBytes(_importCode)

ÍIvÈ4-0ÇÂ!


'using System.Text.ASCIIEncoding.UTF7.GetBytes(_importCode)
+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?
 
H

Herfried K. Wagner [MVP]

JimmyKoolPantz said:
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.
 
J

JimmyKoolPantz

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(_filepath, FileMode.Open)
br = New BinaryReader(fs_Reader)
bw = New BinaryWriter(fs_Reader, System.Text.Encoding.Unicode)

For inum As Integer = 0 To _recordCount - 1
If (al(int) = "IMPORTCODE") Then
_importCode = GetImportCode(temp)
_scanCode = System.Text.Encoding.Unicode.GetBytes(_importCode)



ElseIf (al(int) = "SCANCODE") Then
Mark = fs_Reader.Position - Field_Length
bw.Seek(Mark, SeekOrigin.Begin)
bw.Write(_scanCode, 0, 13)
end if
Next
 

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