Insert Number variation - Letters (alphabetical series)

Help with writing and running scripts

Insert Number variation - Letters (alphabetical series)

Postby caserichard » Tue May 25, 2010 1:26 pm

Hi Folks,
I'm trying [without luck] to create a script. My intention is to make an alphabet version of the Insert Number command in column mode (A,B,C...).

My attempt might not be worth your time as I'm not much of a programmer just yet. Still, I'm including something to give you an idea of what I'm try to achieve. Is there anyone who would like to help and undertake this challenge? Would this script be useful for anyone else?

Code: Select all
if columnMode {                                     /* only run if in column mode (and I want to enforce that more than 1 line is selected)*/
var thelines = UltraEdit.activeDocument.selection;  /* need to count how many lines are selected in column mode, though no characters are actually selected-- it's just the thin Column line; Word Count counts lines like this */
var rows = thelines.length;                         /* and then capture that line count into variable "rows" */
var Alph = new Array();
Alph = [A,B,C,D,E,F,G,H,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z]; /* is this how to make an array? might include AA,AB,AC, etc. if this is a good approach and not too slow */
for (var i = 0; i < rows.length; i++) {
UltraEdit.activeDocument.write(Alph[i]);                   /* output the first character "A" */
UltraEdit.activeDocument.gotoLineSelect(1,0);              /* go to the next line in the column, loop */
}
}

It might even be cooler to have an input dialog to begin the script that asks for the first letter in the series (i.e. to begin from E, the [4]th item in Alph), but this is just something fun to consider for those who enjoy writing scripts. I enjoy the simple ones I can do, but this is all as beyond me. Any help you can offer in approaching a workable script would be wonderful! :)

Thanks,
Rick
caserichard
Newbie
 
Posts: 3
Joined: Thu Dec 18, 2008 1:12 am

Re: Insert Number variation - Letters (alphabetical series)

Postby Mofi » Tue May 25, 2010 2:32 pm

Following script works with UE v16.10 Beta 3. But the first if condition requires UE v16.00 or later. The script is just a first quick draft.

Code: Select all
var nIndex = 0;
var sMarker = "»";
asNumList = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

// if (UltraEdit.outputWindow.visible == false) UltraEdit.outputWindow.showWindow(true);

if (UltraEdit.columnMode == true) {
//   UltraEdit.outputWindow.write("Column mode is ON.");
   if (UltraEdit.activeDocument.isSel()) {
//      UltraEdit.outputWindow.write("There is a selection in column mode.");
      UltraEdit.activeDocument.columnInsert(sMarker);
      UltraEdit.activeDocument.top();
      nIndex = UltraEdit.getValue("Starting value (0="+asNumList[0]+", 1="+asNumList[1]+", ...)?",1);
      if (nIndex < 0 || nIndex >= asNumList.length) nIndex = 0;
      UltraEdit.activeDocument.findReplace.mode=0;
      UltraEdit.activeDocument.findReplace.matchCase=true;
      UltraEdit.activeDocument.findReplace.matchWord=false;
      UltraEdit.activeDocument.findReplace.regExp=false;
      UltraEdit.activeDocument.findReplace.searchDown=true;
      UltraEdit.activeDocument.findReplace.searchInColumn=false;
      while (UltraEdit.activeDocument.findReplace.find(sMarker)) {
         UltraEdit.activeDocument.write(asNumList[nIndex]);
         if (++nIndex >= asNumList.length) nIndex = 0;
      }
   } // else UltraEdit.outputWindow.write("There is nothing selected in column mode.");
} // else UltraEdit.outputWindow.write("Column mode is OFF.");
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4069
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Scripts