#8390
ToadLoadin
Member

Hi zhouzh2,

I modified your macro to this:

cfg = document.Config;
var userVSsetting = cfg.General.VirtualSpace;
cfg.General.VirtualSpace = 'true';
cfg.Save(); //enable VirtualSpace so that when inserting at '^a=nb=n...' will run normally.

var i = prompt("Please enter the start number (not larger than 99)", 0);
var n = prompt("Please enter the end number (not larger than 99)", 1); //promote

if ((i == "")|| (n == "")){Quit();};
if ((i > 99)|| (i < 0) || (n > 99)||(n < 0)) {alert("Error!"); Quit();}; //errors

// Get current cursor position
var iCol = document.selection.GetActivePointX(eePosLogicalA);
var iLine = document.selection.GetActivePointY(eePosLogical);
// Caculate the number of lines
var nLines = Math.abs(i-n)+1;

status = "Inserting - Please Wait...";

for (var j=0; j < nLines; j++) {
document.selection.SetActivePoint(eePosLogicalA, iCol, iLine+j);
if (i < n) { //ascending
document.selection.Text = i;
i++;
} else { //descending
document.selection.Text = i;
i--;
}
}

cfg.General.VirtualSpace = userVSsetting;
cfg.Save();
status = "Inserting Completed";
Quit();

And observed an interesting issue, as you noticed:

when 1<i10, or when 10<i<=99 and n<10

The first number inserted will be the biggest one, I guess that’s why your macro fall into a infinite loop, but I can not figure out why this happens, perhaps a bug? 8-)