Example of Code Page Conflicts in .NET COBOL

Note: The following applies to .NET COBOL only.

Visual Studio creates partial classes in COBOL to give programmatic access to WPF and WCF user interfaces. These partial classes are auto-generated and can then be updated by you or Visual Studio.

In the following example:

If PicLen.cbl is previously existing code or is a new hand-entered source file, it is not encoded using the platform default code page. For example, in the United Kingdom this is code page 1252, or on a Japanese locale machine, it is most likely the Shift-JIS code page 932.

When PicLen is called from WindowStuff, as follows, one code page calls another:
       call "PicLen" using stuff lStuff

Calling one code page from another is not supported directly. The COBOL run-time system generates an error when the application is run. The following source code for Window1 shows the code that handles this and displays the exception:

try
           set stuff to self::textBox1::Text
           call "PicLen" using stuff lStuff
           move lStuff to nStuff
           set self::textBox2::Text to nStuff::ToString()
       catch ex
           set self::textBox3::Text to ex::Message
       end-try

When PicLen and Window1 are encoded in different code pages, the application produces the following exception:

198 Load failure [Program has an incompatible codepage dependency 
CodePageStuff.StrLen is using codepage Western European (Windows) 
but the first program CodePageStuff.Window1 is using Unicode (UTF-8)]