Macro to increment values and update text

Macro to increment values and update text

1
NewbieNewbie
1

    Apr 09, 2007#1

    Hi there,

    Not sure if this can be done but I would sure like to see if someone knows how to do this:

    Old text:
    <book1>
    <author>ABC</author>
    <author>DEF</author>
    <author>GHI</author>
    </book1>
    <book2>
    ...
    ...
    etc.

    Is there a way to use a macro that can change the author tags to:
    <author1>ABC</author1>
    <author2>DEF</author2>
    <author3>GHI</author3>

    Essentially this is a search and replace but the value that gets replaced is based on the prior author number.

    There are many books in the file and the author tags are variable and may have 1 to many authors.

    Many thanks in advance,
    JL

    6,681583
    Grand MasterGrand Master
    6,681583

      Apr 09, 2007#2

      This macro should do the job. It is not very elegant, but it will work for books with a maximum of 20 authors. How it works:

      First a new file is created which is needed as temporary buffer and user clipboard 9 is selected.

      From top of the file a loop is executed where first command searches for start of the book block. If not found anymore, the loop will be exited. The selection after finding the start of a book block is expanded to end of the book block with a second find.

      This selected book block is then copied to the new empty file where from top of the file exactly 20 single replaces are done to insert the number. Not very intelligent, but effective. Add additional replaces if necessary or remove someone, if 20 is surely too much.

      Then the modified block is cut from the temp buffer and pasted over the still existing selection in the source file.

      Moving cursor to end of the line and then inserting a space which is immeditately deleted seems to be useless, but without it, the following Find at top of the loop will not work. Seems to be a synchronization problem of UE at least on my slow computer with UE v11.20a.

      After the loop, the cursor is moved back to top of the file, remaining content of user clipboard 9 is cleared, the Windows clipboard is selected again and the temp file is closed without saving it.

      The macro property Continue if a Find with Replace not found must be checked for this macro.

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      NewFile
      NextWindow
      Clipboard 9
      Top
      Loop
      Find MatchCase "<book"
      IfNotFound
      ExitLoop
      EndIf
      StartSelect
      Find MatchCase Select "</book"
      Copy
      EndSelect
      PreviousWindow
      Paste
      Top
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author1^11>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author2^12>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author3^13>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author4^14>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author5^15>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author6^16>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author7^17>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author8^18>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author9^19>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author10^110>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author11^111>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author12^112>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author13^113>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author14^114>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author15^115>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author16^116>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author17^117>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author18^118>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author19^119>"
      Find MatchCase RegExp "<author^(>*</author^)>"
      Replace "<author20^120>"
      SelectAll
      Cut
      NextWindow
      Paste
      Key END
      " "
      Key BACKSPACE
      EndLoop
      Top
      ClearClipboard
      Clipboard 0
      PreviousWindow
      CloseFile NoSave

      Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.
      Best regards from an UC/UE/UES for Windows user from Austria