Tapatalk

Find text in 2nd file, that was copied in 1st file

Find text in 2nd file, that was copied in 1st file

11
Basic UserBasic User
11

    Jan 06, 2017#1

    I have 2 files open. I want to select and copy text from the first file and then find that selected text in the second file. Can I get a macro to do that? In normal editor mode, after the 1st select/copy I have to move to the second file, select FIND, paste in the select buffer and then click NEXT. I'm struggling to get this done in a macro

    6,685587
    Grand MasterGrand Master
    6,685587

      Jan 06, 2017#2

      What you do could be also done without copying selected text to clipboard by
      • selecting the text in active file,
      • opening regular find window resulting in using the selected text automatically as string to find,
      • switch now to the other file while find window is still opened in foreground (or docked in case of using docked find window),
      • run the find on new active file.
      Searching for selected text in other file without usage of clipboard would be also possible using an UltraEdit script as the script environment supports string variables and make it possible to perform actions on any file via documents array and not just on the active file.

      But you have asked for an UltraEdit macro solution and here it is using user clipboard 9 as buffer for selected text.

      Code: Select all

      IfSel
      InsertMode
      ColumnModeOff
      Clipboard 9
      Copy
      NextWindow
      UltraEditReOn
      Find "^c"
      ClearClipboard
      Clipboard 0
      EndIf
      
      The help page of Find/Replace/Find in Files/Replace in Files can be opened by pressing key F1 on floating Find and Replace window being opened and having input focus. On help page for Find command is described ^c for referencing contents of active clipboard and ^s for referencing selected text in active file. See also Usage of ^c (clipboard content) and ^s (selected text) in search and replace.

      Some additional notes regarding the macro:

      The Find executed from within a macro is always from current caret position in active file to bottom of the file. The configuration setting Continue find at end of file being by default enabled is not active on running a find from within a macro or script to avoid an endless running macro/script.

      If the macro property Continue if search string not found is not checked for this macro, the last three macro commands are not executed if the searched string could not be found in other file after displayed the message box that the searched string is not found. This results in user clipboard 9 still containing the copied string and being still the active clipboard instead of Windows clipboard. Ctrl+C and Ctrl+V in opened Find window as wells as copying/pasting to other applications works only with Windows clipboard. Therefore it is better to use as fourth macro line Clipboard 0 and remove ClearClipboard and Clipboard 0 from bottom of macro on having macro property Continue if search string not found not checked.

      But with a checked macro property Continue if search string not found nothing is displayed if the string is not found from current caret position to end of file.

      So it might be better to use an UltraEdit script for this task which can check for current position of caret in file to search and roll over to beginning if needed with restoring initial caret position in case of string not found anywhere in file and which can also show a message box if the string could not be found in entire file.
      Best regards from an UC/UE/UES for Windows user from Austria

      11
      Basic UserBasic User
      11

        Jan 07, 2017#3

        Thanks. I used the version with Clipboard 0 only and it works great.

        Thanks a lot