471,071 Members | 1,319 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,071 software developers and data experts.

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

ÍIvÈ4-0ÇÂ!
'using System.Text.ASCIIEncoding.UTF7.GetBytes(_importCod e)
+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?
Jul 21 '08 #1
2 2660
"JimmyKoolPantz" <ko*******@gmail.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/>

Jul 22 '08 #2
On Jul 22, 12:53*pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@gmx.atwrote:
"JimmyKoolPantz" <kohl.m...@gmail.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(_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



Jul 22 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by RWK | last post: by
3 posts views Thread by Maris Janis Vasilevskis | last post: by
9 posts views Thread by Roger Withnell | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.