I get some strange results with my little function that should cut out some lines, paste them into a new file, save + close it and return back to the previous file:
Ok, the problem is:
The first time the function is called, the 45 lines are correctly selected, cut out and pasted into the new file. After the new file was saved and closed, the original file has correctly gotten the focus again.
But now in the second run of the loop (the one that calls the function), something goes terribly wrong: The next 45 lines are NOT cut out. Instead, the same clipboard content of the first run is used. Nevertheless, everything else works - a new file is created and so on and I don't receive any error.
I now discovered that everything works well if I replace activeDocument by, lets say, document[0]. Obviously, this is a big disadvantage. I think I could get around this by getting the index of the active document but this is only a hack - why does is not work with activeDocument?
Code: Select all
file_path = "C:\\ba\\inputfiles\\"
for (var f = 1; f < 5; f++) {
sep_HCM_files(file_path + "hcm_in_" + f + ".txt");
}
function sep_HCM_files(fname) {
UltraEdit.activeDocument.key("CTRL+HOME");
UltraEdit.activeDocument.startSelect();
for (var i = 0; i < 45; i++) {
UltraEdit.activeDocument.key("DOWN ARROW");
}
UltraEdit.activeDocument.endSelect();
UltraEdit.activeDocument.cut();
UltraEdit.newFile();
UltraEdit.activeDocument.paste();
UltraEdit.saveAs(fname);
UltraEdit.closeFile(fname, 2);
}
The first time the function is called, the 45 lines are correctly selected, cut out and pasted into the new file. After the new file was saved and closed, the original file has correctly gotten the focus again.
But now in the second run of the loop (the one that calls the function), something goes terribly wrong: The next 45 lines are NOT cut out. Instead, the same clipboard content of the first run is used. Nevertheless, everything else works - a new file is created and so on and I don't receive any error.
I now discovered that everything works well if I replace activeDocument by, lets say, document[0]. Obviously, this is a big disadvantage. I think I could get around this by getting the index of the active document but this is only a hack - why does is not work with activeDocument?