mibuso.com

Microsoft Business Solutions online community
It is currently Mon May 20, 2013 3:04 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: NAV character set conversion utility functions (v2)
PostPosted: Mon May 05, 2008 10:59 am 
Offline
Site Admin

Joined: Sun Nov 07, 1999 8:01 am
Posts: 1900
Location: Wilrijk, Belgium
Country: Belgium (be)
NAV character set conversion utility functions
This codeunit provides two functions to convert between Navision's internal character set and Windows ANSI. The function CodepageConvert is for data imported into Navision ExportCodepageConvert for data leaving Navision.

The codeunit will work with any localisation but it's currently optimised for US or GB. If the codeunit is run from the object designed a piece of code will be displayed that can be merged into the SetUpCharTX function to improve startup speed for the current character set.

http://www.mibuso.com/dlinfo.asp?FileID=959

Discuss this download here.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 05, 2008 4:32 pm 
Offline

Joined: Thu Jul 17, 2003 10:52 pm
Posts: 638
Location: Capelle a/d IJssel
Country: Netherlands (nl)
Hi, you are using a trick to save the characters above 128 to a file and then reading it again. Why? it must work but I can't understand the reason. This seams to be a better solution then the ascii to ansi codeunit. Is it.

Sorry, for asking this.. but this codepage,asni, unicode conversion is driving me ](*,)

_________________
Create dynamic Excel or Word documents, ReportX


Top
 Profile  
 
 Post subject: Short Navsion character set tutorial.
PostPosted: Tue May 06, 2008 4:03 pm 
Offline

Joined: Tue May 06, 2008 2:56 pm
Posts: 350
Location: Walton-On-Thames
Country: United Kingdom (uk)
Using the FSO (File System Object) is probably a better solution if you just want to read or write a simple file, the read whole file I do will obviously only work for a tiny file but the other methods are fine.

BUT using this codeunit allows the functionality built into dataports to be used on unamerican files as well as BLOB functions.

As for WTF Navision is doing ... I trust this will answer most of that ...

Navision Character Sets
-----------------------

Any one Windows Machine has two standard 8-bit character sets normally called ANSI and OEM, on a US machine the ANSI is CP1252 and the OEM is CP437.

Windows has to convert between these character sets and it's native unicode character set for many operations, fortunatly most of these translations are transparent so the applications don't have to worry about them.

However, Navision uses the OEM character set rather than the more normal ANSI character set for it's internal processing this leads to the character set problems that are so common with Navision.

Conversions that work
---------------------

The GUI uses the ANSI character set so you can use (for example) the euro character that's not in the OEM set. (Including copy and paste)
The link to the database uses a conversion to unicode so the database can be setup either in the ANSI or the OEM character sets.
The Automation BSTR type is a unicode string and is converted, so any automation object that uses BSTRs will have proper conversions.

No Conversion Applied
---------------------

The Navision FILE type does not convert so files are assumed to be using the OEM character set.
The Navision dataports do not convert so dataported files are assumed to be using the OEM character set.
Export to text from the object designer does not convert, the Navision text objects are therefore using the OEM character set.
BLOB Import and Export do NOT convert either.
Read and writing BLOBs does not convert.

_________________
Robert de Bath
TVision Technology Ltd


Top
 Profile  
 
 Post subject: NAV character set conversion utility functions (v2)
PostPosted: Wed May 20, 2009 10:46 am 
Offline
Site Admin

Joined: Sun Nov 07, 1999 8:01 am
Posts: 1900
Location: Wilrijk, Belgium
Country: Belgium (be)
NAV character set conversion utility functions (v2)
This codeunit converts between the Navision internal character set (The windows OEM set) and the windows Ansi character set. The most common use for this is in conjunction with dataports, but, it is needed in several other places such as File variables, BLOBS and any other external interface that bypasses Navision's character conversions.

This will work for all Navision languages and needs only the Navision standard hash DLL for configuration.

Known codepage pairs in windows.
1250 852 - CE
1251 855 - Serbian (old Russian)
1251 866 - RU
1252 437 - US
1252 850 - WE
1253 737 - Greek
1254 857 - Turkish
1255 862 - Hebrew
1256 720 - Arabic
1257 775 - Baltic

Also any language where the Ansi and OEM codepages are the same will work correctly.

http://www.mibuso.com/dlinfo.asp?FileID=959

Discuss this download here.


Top
 Profile  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Thu Jun 04, 2009 1:14 pm 
Offline

Joined: Tue May 06, 2008 2:56 pm
Posts: 350
Location: Walton-On-Thames
Country: United Kingdom (uk)
Oops, wrong version.
The line reading:

FOR I := 1 TO 256 DO STR[I] := STR[I] - 7 * (STR[I] MOD 64);

Should read:

FOR I := 1 TO 256 DO STR[I] := STR[I] - 7 * (STR[I] DIV 64);

Sorry. :oops:

_________________
Robert de Bath
TVision Technology Ltd


Top
 Profile  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Thu Jun 04, 2009 10:47 pm 
Offline
MVP Microsoft Dynamics NAV
Site Supporter

Joined: Fri Jun 06, 2003 9:01 pm
Posts: 6977
Location: L.I., New York
Country: United States (us)
what do you mean by..

Quote:
To make this unnecessary in Navision.
Start->Run->regedit
Go to [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage]
And change the "OEMCP" value to "1252" (or the same as ACP)
Reboot


Can you explain what will happen. My OEMCP is 437

_________________
Harry Ruiz
http://www.cosmeticsolutions.com
http://www.autismspeaks.org


Top
 Profile E-mail WWW  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Fri Jun 05, 2009 1:19 pm 
Offline

Joined: Tue May 06, 2008 2:56 pm
Posts: 350
Location: Walton-On-Thames
Country: United Kingdom (uk)
Windows has two standard 8-bit character sets normally called ANSI and OEM, on a US machine the ANSI is CP1252 and the OEM is CP437 as I described above.

Most of the time the OEM character set isn't relevent to users and they can ignore it completely, but Navision uses it for it's internal character set.

The change makes the OEM character set the same as the Ansi character set on a system-wide basis. Windows works fine with this for most codepages (don't try UTF-8 windows won't boot with UTF-8) but some applications may get confused. As it doesn't normally gain you much Microsoft don't push it but Naivison an most other applications work perfectly well and Navision will then be using the normal CP1252 as it's internal character set not the DOS character set.

The only applications that are likely to get upset are some old DOS programs.

_________________
Robert de Bath
TVision Technology Ltd


Top
 Profile  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Fri Dec 04, 2009 8:22 pm 
Offline

Joined: Wed Feb 18, 2009 10:49 pm
Posts: 4
Location: Aguascalientes
Country: Mexico (mx)
Hi everyone!!!

My customer is trying to import a txt file into a database with a Greek collation, this txt file has Greek characters but when this file is being imported into NAV all the Greek characters has been a total mess. It doesn't respect these Greek characters.

So my questions will be, do this NAV character conversion utility function will work for this puprpose? How am I supposed to use it? When it's supposed to be executed? Into the dataport after the txt file has been read or before the read of the data? Which function of this codeunit am I supposed to call into the code of the dataport for the import functionality?
If this codeunit does not help me, does anyone knows anything on how can I import a txt file with Greek characters into a database with Greek collation?

Any help will be really appreciated.

Receive many kind regards.


Top
 Profile E-mail  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Fri Dec 04, 2009 8:39 pm 
Offline

Joined: Tue May 06, 2008 2:56 pm
Posts: 350
Location: Walton-On-Thames
Country: United Kingdom (uk)
This should do the trick; don't forget the repair on the FOR loop.

The simplest way to use it is to put into the OnAfterImportRecord() a line like this:

Description := Cvt.CodepageConvert(Description);

For every text field.

The second simplest option is to put a similar line into each OnBeforeEvaluateField
ie:
Text := Cvt.CodepageConvert(Text);

DONT DO BOTH.

_________________
Robert de Bath
TVision Technology Ltd


Top
 Profile  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Fri Dec 04, 2009 9:20 pm 
Offline

Joined: Wed Feb 18, 2009 10:49 pm
Posts: 4
Location: Aguascalientes
Country: Mexico (mx)
Hi Robert!

Thank you very much for your reply on my question about how to import a txt file with Greek characters into a database with Greek collation!!!

I just have one doubt left, on your first statement you said that I shouldn't forget the repair on the FOR loop, what do you mean by that? As I'm not familiar with this NAV character set conversion utility codeunit I don't completely understand that, if you can clarify me this I will be very grateful.

Receive many kind regards.

Emanuel Galvan.


Top
 Profile E-mail  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Sat Dec 05, 2009 8:11 pm 
Offline

Joined: Tue May 06, 2008 2:56 pm
Posts: 350
Location: Walton-On-Thames
Country: United Kingdom (uk)
I meant this: viewtopic.php?f=7&t=25554#p169404

_________________
Robert de Bath
TVision Technology Ltd


Top
 Profile  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Mon Oct 18, 2010 4:22 pm 
Offline

Joined: Fri May 04, 2007 11:50 am
Posts: 11
Location: Germany
Country: Germany (de)
Hi,

i want to use the function ExportCodepageConvert to solve a problem with exporting Hebrew letters but i get the atteched error. Can somebody help me ?


Attachments:
error.jpg
error.jpg [ 12.46 KiB | Viewed 8367 times ]
Top
 Profile  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Mon Oct 18, 2010 4:33 pm 
Offline

Joined: Tue May 06, 2008 2:56 pm
Posts: 350
Location: Walton-On-Thames
Country: United Kingdom (uk)
viewtopic.php?p=169404&sid=399bbbfff9662737c326c3b46dc89531#p169404

I should remember to upload a new version.

_________________
Robert de Bath
TVision Technology Ltd


Top
 Profile  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Mon Feb 14, 2011 9:48 pm 
Offline

Joined: Thu Dec 01, 2005 5:51 pm
Posts: 54
Location: Toronto
Country: Canada (ca)
I am trying to use codeunit NAV character set conversion utility functions (v2).
I am using the following code:

MyText := ‘Église Pentecôte de la Vallée Richelieu’;
ConvertCU.ExportCodepageConvert(MyText);
MyFile.TEXTMODE := TRUE;
MyFile.WRITEMODE := TRUE;
MyFile.CREATE(MyFileName);
MyFile.WRITE(MyText);

When I open created text file, it is still showing wrong string, like glise Pentec“te de la Vall‚e Richelieu.
I tried to change register according to the following instructions and it helped. I changed OEMCP from 437 to 1252.

Start->Run->regedit
Go to [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage]
And change the "OEMCP" value to "1252" (or the same as ACP)
Reboot


After that I got proper string in my text file, even without using ExportCodepageConvert function: Église Pentecôte de la Vallée Richelieu

So, I have a solution, but I am trying to get it work without changing a register. Can you advise, please, what could be wrong in my code above?


Top
 Profile  
 
 Post subject: Re: NAV character set conversion utility functions (v2)
PostPosted: Tue Feb 15, 2011 8:35 pm 
Offline

Joined: Tue May 06, 2008 2:56 pm
Posts: 350
Location: Walton-On-Thames
Country: United Kingdom (uk)
The function returns the converted string; you use:

MyText :=ConvertCU.ExportCodepageConvert(MyText);


The registry change is NOT recommended, while it doesn't usually cause problems it is in general of little use.

_________________
Robert de Bath
TVision Technology Ltd


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: