NAV character set conversion utility functions (v2)

AdministratorAdministrator Posts: 2,254Member, Moderator, Administrator
edited 2012-06-28 in Download section
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.

Comments

  • ajhvdbajhvdb Posts: 672Member
    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 ](*,)
  • rdebathrdebath Posts: 383Member
    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
  • AdministratorAdministrator Posts: 2,254Member, Moderator, Administrator
    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.
  • rdebathrdebath Posts: 383Member
    Oops, wrong version.
    The line reading:

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

    Should read:

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

    Sorry. :oops:
    Robert de Bath
    TVision Technology Ltd
  • SavatageSavatage Posts: 7,134Member
    what do you mean by..
    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
  • rdebathrdebath Posts: 383Member
    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
  • Emanuel_Folken23Emanuel_Folken23 Posts: 6Member
    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.
  • rdebathrdebath Posts: 383Member
    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
  • Emanuel_Folken23Emanuel_Folken23 Posts: 6Member
    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.
  • rdebathrdebath Posts: 383Member
  • BT_MarcBT_Marc Posts: 21Member
    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 ?
    error.jpg
    12K
  • rdebathrdebath Posts: 383Member
    viewtopic.php?p=169404&sid=399bbbfff9662737c326c3b46dc89531#p169404

    I should remember to upload a new version.
    Robert de Bath
    TVision Technology Ltd
  • alex9alex9 Posts: 95Member
    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?
  • rdebathrdebath Posts: 383Member
    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
  • pawanadppawanadp Posts: 1Member
    Hi,

    Any one knows does this tool support Korean Db.

    I get an following error in funtion DynamicTx()

    Microsoft Dynamics NAV
    The indexing 0 in the array is outside of the permitted range.

    OK

    Code Breaks on Line : FOR I := 255 DOWNTO 128 DO CharTXr[CharTX] := I;

    It runs fine for other languages for eg China,japan,russia but gives error in Korea.

    Is Korea character set is not supported.

    Report Code is '68211afe1fd006ff5629d50f28a2af3c'

    Please suggest.

    Regards
    Pawan
Sign In or Register to comment.