Quick macro prob. data file query via macro.

Help with writing and playing macros

Quick macro prob. data file query via macro.

Postby PHPeople » Mon Sep 18, 2006 5:56 am

I have been looking for these on msg boards, and am finding things more elaborate then what I need. Sorry to repeat post on the subjects...

I have a 12 meg text file. I want to use it as reference for a macro driven lookup, or aka a huge index file. I want to open this text file, run a macro, utilize GetValue, ask the question "Search Term?" and then go start from the bottom and work its way up. I prefer Reg Expression. Now, once it finds the phrase of data, I would prefer a line copy, I would also like to use that list option to display where it shows other references in the entire doc. That is so cool. All info is much appreciated, I love this program, never have time to play with it.

Here, I will give you a laugh.. I am probably way off.. but

Bottom
Key Ctrl+END
GetValue "Search Term?"
<I type some search term>
Find RegExp Up "%1 " <whatever the equivalent is in UltraEdit>
IfFound hightlight
Copy
<end macro>

ThankYou!
User avatar
PHPeople
Newbie
 
Posts: 1
Joined: Sun Sep 17, 2006 11:00 pm

Re: Quick macro prob. data file query via macro.

Postby Mofi » Mon Sep 18, 2006 10:25 am

I don't know why you need a macro for this job, but however, here is it. The macro property Continue if a Find with Replace not found must be checked for this macro.

Please note:

1) A regular expression search with a variable string - here with the string you entered copied to user clipboard 9 - is only possible with the UltraEdit regular expression engine. It's not possible with the legacy Unix or the Perl engine. So the macro uses the command UnixReOff to switch to the UltraEdit engine and you must enter the regex search string with UltraEdit syntax.

2) A regular expression search upwards often fails where it finds the string downwards. Maybe it would be better to first search from top of the file down and copy the line where it was found last if at least found once - see macro solution 2.

3) To highlight all occurences of the string in the whole file like with the find option Highlight All Items Found is not possible from within a macro. You can see this easily if you record a find with this option checked and look at the recorded macro code. You will not see a single Find command with an appropriate parameter, you will see as many find commands as needed to find all occurences of the searched string in the file from current cursor position.

Solution 1 with regular expression find upwards:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Bottom
IfColNum 1
Else
"
"
EndIf
GetString "Search Term?"
StartSelect
Key HOME
Key HOME
Clipboard 9
Cut
EndSelect
Find RegExp Up "^c"
IfFound
SelectLine
Clipboard 0
Copy
EndSelect
Key UP ARROW
Clipboard 9
Find RegExp "^c"
EndIf
ClearClipboard
Clipboard 0


Solution 2 with regular expression find downwards and only the line with the last occurence is copied to the windows clipboard:

InsertMode
ColumnModeOff
HexOff
UnixReOff
Bottom
IfColNum 1
Else
"
"
EndIf
GetString "Search Term?"
StartSelect
Key HOME
Key HOME
Clipboard 9
Cut
EndSelect
Top
Find RegExp "^c"
IfFound
Loop
Find RegExp "^c"
IfNotFound
ExitLoop
EndIf
EndLoop
SelectLine
Clipboard 0
Copy
EndSelect
Key UP ARROW
Clipboard 9
Find RegExp "^c"
EndIf
ClearClipboard
Clipboard 0
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4055
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna


Return to Macros