Hi Dave,
very well done for a macro newbie!
I looked on your macro code and made some changes. First I loaded the macro code into an
UEM file (UE/UES macro code file) with my syntax highlighting for my macros and used Format - ReIndent Selection.
With indentations I could see that in all my macros I have had a small mistake: there was an EndIf too much before EndLoop. I corrected this in all my previous posts.
Then I started to improve your macro. First I thought, it would be a good idea to check if there is a selection and if not, select whole file by the macro. Then the user doesn't need it to do when he wants to run the macro on the whole file.
Next I just copied the selection to the new file instead of cutting it. This gives you the possibility to break the macro execution with ESC key or by pressing the Cancel button at any time without any modification in the source file untill renumbered selection is pasted back over still existing selection in the source file.
The macro does immediately after pasting the selection to the new file the check for termination of last line because the cursor is now after the paste already at bottom of the file (speed improvement).
Next the user must enter the starting number - yes, the real starting number. And the user must enter the increment value. Well, only incrementing by 1, 2, ... 9 is supported by this macro. So this GetValue is enclosed in a loop until the user has correctly entered the increment. The single digit increment number is stored in clipboard 8.
The first renumbering is done now outside the loop above the loop. This makes it possible to simply paste the starting number without using macro CountUp.
Then after first renumbering the loop is executed.
To be able to run an individual increment of 1-9, the macro evaluates the before entered increment number and calls the macro CountUp according to it's value. This is not a very good solution, because it works only for increments of 1-9. But maybe it is enough. A full support for any increment number greater than 0 would require a CountDown macro which executes CountUp until the entered increment number gets 0. That would be possible, but very slow. Using the JavaScript engine introduced with UltraEdit v13 or UEStudio v6.20 would be the much better and faster solution for this job.
The rest of the macro has only some small changes, nothing important.
Here is the improved macro which also requires macro property
Continue if a Find with Replace not found enabled.
InsertMode
ColumnModeOff
HexOff
UnixReOff
Clipboard 9
IfSel
Else
SelectAll
EndIf
Copy
NewFile
Paste
IfColNum 1
Else
"
"
EndIf
Top
"
"
Key UP ARROW
GetValue "Enter Starting N-Block Number"
StartSelect
Key HOME
Cut
EndSelect
Loop
GetValue "Increment Number [1-9]"
IfColNum 2
Key LEFT ARROW
IfCharIs "123456789"
StartSelect
Key RIGHT ARROW
Clipboard 8
Cut
EndSelect
ExitLoop
Else
Delete
EndIf
Else
StartSelect
Key HOME
Delete
EndSelect
EndIf
EndLoop
DeleteLine
Clipboard 9
Find MatchCase RegExp "%[~^%(O^r^n]"
IfFound
EndSelect
Key HOME
IfCharIs "N"
Find MatchCase RegExp "%N[0-9]+"
EndIf
Paste
Key HOME
"N"
Key HOME
StartSelect
Key END
Find RegExp "^([A-Z][0-9.^-]+^)"
Replace All SelectText "^1 "
EndSelect
Key HOME
Key DOWN ARROW
EndIf
Loop
Find MatchCase RegExp "%[~^%(O^r^n]"
IfNotFound
ExitLoop
EndIf
EndSelect
Key HOME
IfCharIs "N"
Find MatchCase RegExp "%N[0-9]+"
Delete
EndIf
Clipboard 8
Paste
Clipboard 9
Key LEFT ARROW
IfCharIs "1"
Delete
PlayMacro 1 "CountUp"
Else
IfCharIs "2"
Delete
PlayMacro 2 "CountUp"
Else
IfCharIs "3"
Delete
PlayMacro 3 "CountUp"
Else
IfCharIs "4"
Delete
PlayMacro 4 "CountUp"
Else
IfCharIs "5"
Delete
PlayMacro 5 "CountUp"
Else
IfCharIs "6"
Delete
PlayMacro 6 "CountUp"
Else
IfCharIs "7"
Delete
PlayMacro 7 "CountUp"
Else
IfCharIs "8"
Delete
PlayMacro 8 "CountUp"
Else
IfCharIs "9"
Delete
PlayMacro 9 "CountUp"
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
Key HOME
"N"
Key HOME
StartSelect
Key END
Find RegExp "^([A-Z][0-9.^-]+^)"
Replace All SelectText "^1 "
EndSelect
Key HOME
Key DOWN ARROW
EndLoop
Top
Find " "
Replace All " "
TrimTrailingSpaces
ClearClipboard
Clipboard 8
SelectAll
Cut
CloseFile NoSave
Paste
ClearClipboard
Clipboard 0
Top
Loop
Find "^p^p"
Replace All "^p"
IfNotFound
ExitLoop
EndIf
EndLoop