Code Page Conversion.

Is there any method in Visual COBOL to do Code Page converison for File CP1250
(windows code page) to CP852 (DOS code page).



  • Hi Partha,

    Are you referring to programatically converting code pages within your application or doing a one time conversion of source code within Visual Studio?

    If it is the latter of the two then you can open up the file in Visual Studio and then select File-->Advanced Save Options and then change the target code page to the one that you desire and then save the file.

    If you wish to do this programmatically then you would look into using the .NET System.Text.Encoding class.

    Please take a look here.

    If you require a COBOL example then let me know exactly what it is that you are trying to do and I will work one up for you.


  • Thanks Chris.

    I want to do this by programatically..regarding few files we received in 1250 nd want to convert in 852. It would be great help if you can refer anu COBOL example.

  • The following might work for you:

          $set ilusing"System.Text" 
          $set ilusing"System.IO" 
           program-id. Program1 as "fileconvert.Program1".
           data division.
           working-storage section.
           01 fileName string value "myfile.txt".
           01 newfileName string value "newfile.txt".
           01 original string value type String::Empty.
           01 sr type StreamReader.
           01 sw type StreamWriter.
           procedure division.
               set sr to new StreamReader(filename, type Encoding::GetEncoding("windows-1250"))
               set original to sr::ReadToEnd 
               invoke sr::Close
               set sw to new StreamWriter(newFilename, false, type Encoding::GetEncoding("ibm852"))
               invoke sw::Write(original)
               invoke sw::Close
           end program Program1.
  • Hi Chris,

    Is this code snippet supports Visual COBOL?

  • Yes, it was written using Visual COBOL 2.2 update 1 for VS2012.

    It is a managed code project and must be compiled as such.

  • Hi Partha,

    Since you need to convert between the ANSI and OEM codeset, the following two routines might work for you:

    PC_WIN_CHAR_TO_OEM (which will convert CP1250 to 852) and PC_WIN_OEM_TO_CHAR that will do the opposite. They are fully described in the product documentation.

    CP1250 should be the active codepage on you machine.