Insert Number variation - Letters (alphabetical series)

Insert Number variation - Letters (alphabetical series)

9

    May 25, 2010#1

    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

    6,675585
    Grand MasterGrand Master
    6,675585

      May 25, 2010#2

      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);
      
      // The column mode property is a property of the UltraEdit object in
      // UltraEdit for Windows and UEStudio, but a property of the document
      // object in UltraEdit for Linux and for Mac.
      var bColumnMode = false;
      if (typeof(UltraEdit.columnMode) == "boolean") bColumnMode = UltraEdit.columnMode;
      else if (typeof(UltraEdit.activeDocument.columnMode) == "boolean") bColumnMode = UltraEdit.activeDocument.columnMode;
      
      if (bColumnMode) {
      //   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.");
      Best regards from an UC/UE/UES for Windows user from Austria

      9

        Jan 17, 2014#3

        Mofi,
        Thanks again for creating this script. It does the trick! It would be nice if they made it a stock offering eventually. Is there any way to do this so the undo history isn't impacted? Not urgent, just curious.

        First time script users:
        Save this as a .js file in the default typeset (ANSI - Latin I). I have my editor defaulted to UTF-8 and that was breaking the script.

          Jan 17, 2014#4

          Also, I've tweaked it slightly so that all alphabet letters are shown with their partner index number.  This is the script I'm using:

          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);
          
          // The column mode property is a property of the UltraEdit object in
          // UltraEdit for Windows and UEStudio, but a property of the document
          // object in UltraEdit for Linux and for Mac.
          var bColumnMode = false;
          if (typeof(UltraEdit.columnMode) == "boolean") bColumnMode = UltraEdit.columnMode;
          else if (typeof(UltraEdit.activeDocument.columnMode) == "boolean") bColumnMode = UltraEdit.activeDocument.columnMode;
          
          if (bColumnMode) {
          //   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? ("+asNumList[0]+":0 " +
                  asNumList[1]  + ":1 " +
                  asNumList[2]  + ":2 " +
                  asNumList[3]  + ":3 " +
                  asNumList[4]  + ":4 " +
                  asNumList[5]  + ":5 " +
                  asNumList[6]  + ":6 " +
                  asNumList[7]  + ":7 " +
                  asNumList[8]  + ":8 " +
                  asNumList[9]  + ":9 " +
                  asNumList[10] + ":10 " +
                  asNumList[11] + ":11 " +
                  asNumList[12] + ":12 " +
                  asNumList[13] + ":13 " +
                  asNumList[14] + ":14 " +
                  asNumList[15] + ":15 " +
                  asNumList[16] + ":16 " +
                  asNumList[17] + ":17 " +
                  asNumList[18] + ":18 " +
                  asNumList[19] + ":19 " +
                  asNumList[20] + ":20 " +
                  asNumList[21] + ":21 " +
                  asNumList[22] + ":22 " +
                  asNumList[23] + ":23 " +
                  asNumList[24] + ":24 " +
                  asNumList[25] + ":25 )",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.");