convert to fixed column

Help with writing and running scripts

convert to fixed column

Postby fej » Wed Oct 13, 2010 5:12 pm

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!
fej
Newbie
 
Posts: 1
Joined: Wed Oct 13, 2010 4:56 pm

Re: convert to fixed column

Postby Mofi » Thu Oct 14, 2010 12:21 am

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.
UltraEdit.columnModeOn();
UltraEdit.activeDocument.columnInsert(" ");
UltraEdit.activeDocument.columnDelete(1);
UltraEdit.columnModeOff();
// Go to end of file and append a line termination to last line of file.
UltraEdit.activeDocument.bottom();
UltraEdit.activeDocument.insertLine();
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4064
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Scripts