Tapatalk

convert to fixed column

convert to fixed column

1
NewbieNewbie
1

    Oct 13, 2010#1

    Hi all!

    I'm searching for a while a solution to open a file, convert to 133 columns, convert it to ebcdic and save.

    My code :

    Code: Select all

    while(nFileCount--) {
      UltraEdit.open(asFileNames[nFileCount]);		
      UltraEdit.activeDocument.toEBCDIC();
      UltraEdit.activeDocument.wrapToReturn(133);
      UltraEdit.closeFile (UltraEdit.activeDocument.path,1);
      };
    My problem is : if I have a line with 33 characters, the 'wrapToReturn' function doesn't fill the 34 to 133 columns with a blank. But, by the interface, the command "Columns-> convert to fixed column" everything works. 8O

    Thanks for helping!

    6,685587
    Grand MasterGrand Master
    6,685587

      Oct 14, 2010#2

      Insert the following script code lines into your script before saving and closing the file.

      Code: Select all

      // Go to end of file. If the last line of the file has a line termination,
      // remove this line termination temporarily. Otherwise the file would later
      // end with 132 spaces which is not wanted.
      UltraEdit.activeDocument.bottom();
      if (UltraEdit.activeDocument.isColNum(1)) UltraEdit.activeDocument.deleteLine();
      // Go to end of first line.
      UltraEdit.activeDocument.top();
      UltraEdit.activeDocument.key("END");
      // Make sure this line has 132 characters by appending spaces if necessary.
      var nSpacesNum = UltraEdit.activeDocument.currentColumnNum;
      if (typeof(UltraEdit.activeDocumentIdx) == "undefined") nSpacesNum++;
      nSpacesNum = 133 - nSpacesNum;
      var sSpaces = "";
      while (nSpacesNum--) sSpaces += ' ';
      if (sSpaces.length) UltraEdit.activeDocument.write(sSpaces);
      // To make sure that all lines have 132 characters a trick is used to
      // append spaces to those lines with less than 132 characters. Column
      // mode is enabled and a column is inserted and removed. That results
      // in appending spaces to those lines with less than 132 characters.
      if (typeof(UltraEdit.columnModeOn) == "function") UltraEdit.columnModeOn();
      else if (typeof(UltraEdit.activeDocument.columnModeOn) == "function") UltraEdit.activeDocument.columnModeOn();
      UltraEdit.activeDocument.columnInsert(" ");
      UltraEdit.activeDocument.columnDelete(1);
      if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
      else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();
      // Go to end of file and append a line termination to last line of file.
      UltraEdit.activeDocument.bottom();
      UltraEdit.activeDocument.insertLine();
      Best regards from an UC/UE/UES for Windows user from Austria