EmEditor (text editor) Forum Index
   Questions and Answers about Macros
     needs help on a macro to insert number row
Register To Post

Flat Previous Topic | Next Topic
Poster Thread
zhouzh2
Posted on: 3/30/2010 11:18 am
Just can't stay away
Joined: 7/27/2008
From:
Posts: 89
needs help on a macro to insert number row
I wrote this for inserting number row. both in this kind:
a=1
b=2
c=3
..

and:
a = 1  somethinghere
b = 2  somethinghere
c = 3  somethinghere
..

It is supposed to work from number 0 to 99 or 99 to 0.
/*insertNumbers.jsee*/
/*Insert numbers in a row*/

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

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.

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

if (i < n) {
	n++;
	while (i < 10){
		document.selection.Text=i;
		document.selection.LineDown(false,1);
		document.selection.CharLeft(false,1);
		i++;
		if (i == n) {insertEnd();};
	};
	while (i <= 99){
		document.selection.Text=i;
		document.selection.LineDown(false,1);
		document.selection.CharLeft(false,1);
		document.selection.CharLeft(false,1);
		i++;
		if (i == n) {insertEnd();};
	};
}; //ascending

else {
	n--;
	while (i >= 10){
		document.selection.Text=i;
		document.selection.LineDown(false,1);
		document.selection.CharLeft(false,1);
		document.selection.CharLeft(false,1);
		i--;
		if (i == n) {insertEnd();};
	};
	while (i < 10){
		document.selection.Text=i;
		document.selection.LineDown(false,1);
		document.selection.CharLeft(false,1);
		i--;
		if (i == n) {insertEnd();};
	};
}; //descending

function insertEnd(){
	cfg.General.VirtualSpace = userVSsetting;
	cfg.Save();
	status = "Inserting Completed";
	Quit();
};

However, this macro will be trapped in a loop under a certain situation, i.e. when 1<i<10 and n>10, or when 10<i<=99 and n<10 (however the latter will not always appear.) But I cannot find out why. Anyone please help me with that
Flat Previous Topic | Next Topic


Subject Poster Date
 » needs help on a macro to insert number row zhouzh2 3/30/2010 11:18 am
     Re: needs help on a macro to insert number row zhouzh2 4/3/2010 3:34 am
       Re: needs help on a macro to insert number row ToadLoadin 4/5/2010 9:46 pm
         Re: needs help on a macro to insert number row zhouzh2 4/6/2010 8:13 am
           Re: needs help on a macro to insert number row ToadLoadin 4/21/2010 4:49 am
             Re: needs help on a macro to insert number row zhouzh2 4/22/2010 6:36 am
               Re: needs help on a macro to insert number row tonne 4/23/2010 8:58 am
                 Re: needs help on a macro to insert number row ToadLoadin 4/23/2010 5:49 pm
                   Re: needs help on a macro to insert number row tonne 4/24/2010 12:22 am
                     Re: needs help on a macro to insert number row ToadLoadin 4/24/2010 1:55 am

Register To Post
 
English čeština Deutsch español français italiano 日本語 한국어 Русский 简体中文 繁體中文