Macro to increment a value in the file by 1

Macro to increment a value in the file by 1

2
NewbieNewbie
2

    Sep 04, 2009#1

    So I'm on the free trial of UE... fantastic editor! Even with the macro shortcomings.

    The one main thing I needed to do to some huge files is increment some values, and with that functionality not there, I had to write a macro for it, before ever seeing the discussion forums here. I figured I'd share it since I couldn't find a more streamlined version here that didn't use something outside itself like the clipboard or calling another macro.

    When the macro is executed, the cursor MUST be sitting before the LAST character in the number, and "Continue if a Find with Replace not found" MUST be checked. Depending on what the number is, the cursor can end up anywhere in the number or at the end. The macro understands decimal and comma but not leading zeroes.

    The timing loop at the end may have to be adjusted to suit your system.

    Code: Select all

    InsertMode
    ColumnModeOff
    HexOff
    UnixReOff
    IfCharIs "0"
    Key DEL
    "1"
    ExitMacro
    EndIf
    IfCharIs "1"
    Key DEL
    "2"
    ExitMacro
    EndIf
    IfCharIs "2"
    Key DEL
    "3"
    ExitMacro
    EndIf
    IfCharIs "3"
    Key DEL
    "4"
    ExitMacro
    EndIf
    IfCharIs "4"
    Key DEL
    "5"
    ExitMacro
    EndIf
    IfCharIs "5"
    Key DEL
    "6"
    ExitMacro
    EndIf
    IfCharIs "6"
    Key DEL
    "7"
    ExitMacro
    EndIf
    IfCharIs "7"
    Key DEL
    "8"
    ExitMacro
    EndIf
    IfCharIs "8"
    Key DEL
    "9"
    ExitMacro
    EndIf
    IfCharIs "9"
    Key DEL
    "0"
    Key LEFT ARROW
    EndIf
    Loop 
    IfCharIs "0.,"
    Key LEFT ARROW
    EndLoop
    EndIf
    IfCharIs "123456789"
    PlayMacro 1 "Increment"
    Else
    Key RIGHT ARROW
    "1"
    EndIf
    Loop 100
    EndLoop
    /poke IDM "If this proves useful enough I wouldn't mind a complimentary UE license..... otherwise I'll just go back to the freeware editor I was using since my company's too cheap to buy anything worthwhile." :mrgreen:

    6,681583
    Grand MasterGrand Master
    6,681583

      Sep 05, 2009#2

      I think, Sergey Pavlovich Korolyov (or Sergei Pavlovich Korolev or German Sergei Pawlowitsch Koroljow) said once as asked why the Russian Buran looks like US Space Shuttle: "Similar problems result in similar solutions."

      Your macro is similar to my CountUp macro which I have written years ago for having an incrementing integer variable in macros. Your macro is for incrementing positive values (float and integer).

      It's quite good, but has some weaknesses. It deletes the character to increment instead of simply overwriting it in overstrike mode causing an additional unnecessary undo step. And it fails when the number 9 (or 99 or 9.99, ...) is at start of a line because then "1" is inserted at end of the line above or causes the number at end of the line above to be also increased, except configuration setting Disable left cursor from going to previous line is used. Also the recursive call of the macro is not really necessary and therefore the timing loop is not necessary.

      There are 2 other famous quotations from Sergey Korolyov (freely translated from German Wikipedia page):

      The genius of a construction proves to be in its simplicity - making something complex can everybody.
      Let us find a compromise solution - let us do it as I say.

      Here is my macro for increment a value by 1. This macro also requires that the cursor is left the digit which should be increased first which is normally the most left one, except you want to increase a number by 10, 100, 1.00, 0.1, etc.

      Code: Select all

      OverStrikeMode
      ColumnModeOff
      HexOff
      Loop
      IfCharIs "0"
      "1"
      ExitLoop
      EndIf
      IfCharIs "1"
      "2"
      ExitLoop
      EndIf
      IfCharIs "2"
      "3"
      ExitLoop
      EndIf
      IfCharIs "3"
      "4"
      ExitLoop
      EndIf
      IfCharIs "4"
      "5"
      ExitLoop
      EndIf
      IfCharIs "5"
      "6"
      ExitLoop
      EndIf
      IfCharIs "6"
      "7"
      ExitLoop
      EndIf
      IfCharIs "7"
      "8"
      ExitLoop
      EndIf
      IfCharIs "8"
      "9"
      ExitLoop
      EndIf
      IfCharIs ",."
      IfColNum 1
      InsertMode
      "1"
      ExitLoop
      Else
      Key LEFT ARROW
      EndIf
      Else
      IfCharIs "9"
      "0"
      Key LEFT ARROW
      IfColNum 1
      InsertMode
      "1"
      ExitLoop
      EndIf
      Key LEFT ARROW
      IfCharIs ",.0123456789"
      Else
      Key RIGHT ARROW
      InsertMode
      "1"
      ExitLoop
      EndIf
      EndIf
      EndIf
      EndLoop
      InsertMode
      Same as above UEM with indentations:

      Code: Select all

      OverStrikeMode
      ColumnModeOff
      HexOff
      UnixReOff
      Loop
          IfCharIs "0"
              "1"
              ExitLoop
          EndIf
          IfCharIs "1"
              "2"
              ExitLoop
          EndIf
          IfCharIs "2"
              "3"
              ExitLoop
          EndIf
          IfCharIs "3"
              "4"
              ExitLoop
          EndIf
          IfCharIs "4"
              "5"
              ExitLoop
          EndIf
          IfCharIs "5"
              "6"
              ExitLoop
          EndIf
          IfCharIs "6"
              "7"
              ExitLoop
          EndIf
          IfCharIs "7"
              "8"
              ExitLoop
          EndIf
          IfCharIs "8"
              "9"
              ExitLoop
          EndIf
          IfCharIs ",."
              IfColNum 1
                  InsertMode
                  "1"
                  ExitLoop
              Else
                  Key LEFT ARROW
              EndIf
          Else
              IfCharIs "9"
                  "0"
                  Key LEFT ARROW
                  IfColNum 1
                      InsertMode
                      "1"
                      ExitLoop
                  EndIf
                  Key LEFT ARROW
                  IfCharIs ",.0123456789"
                  Else
                      Key RIGHT ARROW
                      InsertMode
                      "1"
                      ExitLoop
                  EndIf
              EndIf
          EndIf
      EndLoop
      InsertMode
      PS: If somebody finds the original quotations from Sergey Korolyov in English which I translated here from German, please post the link to the source for me. Thanks.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Sep 05, 2009#3

        Hmmm I wish I would have found yours first... would have saved me an hour!