kay_dee Posted November 7, 2007 Report Share Posted November 7, 2007 Hi, I am trying to build a macro to determine the exact no. of instances a particular phrase appears in a block of text. I think I am on the right path, but I cannot figure out how to end the repeat at the last instance of that phrase appearing. I have pasted the script I have so far (I hope this is the right way to paste it) <IVAR2:01:01:0><LAUNCHNO3:0:0130Untitled - Notepad<LAUNCH:c:\windows\notepad.exe><CLIPP><TEXTTYPE:<CTRLD><HOME>f<CTRLU>><WAITWIN2:000010:000000:Find><TEXTTYPE:View full details><REP3:05:000001:000001:0001:0:01:><TEXTTYPE:<ENTER>><NMVAR:08:01:0:0000001:0:0000000><IFOTH:03:1:Notepad><TEXTTYPE:<ESC>%N1%><ENDIF><ENDREP> Please help! Quote Link to comment Share on other sites More sharing options...
kay_dee Posted November 7, 2007 Author Report Share Posted November 7, 2007 OK, I updated the macro to save the window name into a variable and end the repeat when a match is made. But it still doesn't work <IVAR2:01:01:0><LAUNCHNO3:0:0130Untitled - Notepad<LAUNCH:c:\windows\notepad.exe><CLIPP><TEXTTYPE:<CTRLD><HOME>f<CTRLU>><WAITWIN2:000010:000000:Find><TEXTTYPE:View full details><CLEARVAR1:A:ALL><REP3:08:000001:000001:0001:0:01:Notepad><CLEARVAR1:T:ALL><TEXTTYPE:<ENTER>><TVAR2:01:06:><NMVAR:08:01:0:0000001:0:0000000><ENDREP><LAUNCHNO3:0:0130Untitled - Notepad<LAUNCH:c:\windows\notepad.exe><TEXTTYPE:<ESC><ESC>%N1%> Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 7, 2007 Report Share Posted November 7, 2007 Hi, I am trying to build a macro to determine the exact no. of instances a particular phrase appears in a block of text. I think I am on the right path, but I cannot figure out how to end the repeat at the last instance of that phrase appearing. I have pasted the script I have so far (I hope this is the right way to paste it) <IVAR2:01:01:0><LAUNCHNO3:0:0130Untitled - Notepad<LAUNCH:c:\windows\notepad.exe><CLIPP><TEXTTYPE:<CTRLD><HOME>f<CTRLU>><WAITWIN2:000010:000000:Find><TEXTTYPE:View full details><REP3:05:000001:000001:0001:0:01:><TEXTTYPE:<ENTER>><NMVAR:08:01:0:0000001:0:0000000><IFOTH:03:1:Notepad><TEXTTYPE:<ESC>%N1%><ENDIF><ENDREP> Please help! Your logic is incorrect in several ways. For example, you have asked the macro to repeat the loop zero times! And where are you viewing your result? I'm no expert myself, so there are probably smarter ways, but the following drastically edited version works OK: <SPKEY:0010><IVAR2:01:01:0><LAUNCHNO3:0:0130Untitled - Notepad<LAUNCH:c:\windows\notepad.exe><CLIPP><TEXTTYPE:<CTRLD><HOME>f<CTRLU>><WAITWIN2:000010:000000:Find><TEXTTYPE:View full details><REP3:08:000001:000002:0002:0:01:999999><TEXTTYPE:<ENTER>><IFOTH:03:1:Notepad><TBOX4:T:4:CenterCenter000278000200:000:ResultThe string 'View full details' appears %N1% times in this file.><TEXTTYPE:<ESC><ESC>><REM2:Close the Find dialog (keeping Notepad open) and STOP the macro at once.><MSTOP><ENDIF><NMVAR:08:01:0:0000001:0:0000000><ENDREP> -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 7, 2007 Report Share Posted November 7, 2007 Here is a slightly tidier version, which also displays the result at the end of your file, as I believe you want: <IVAR2:01:01:0><SPKEY:0010><LAUNCHNO3:0:0130Untitled - Notepad<LAUNCH:c:\windows\notepad.exe><CLIPP><TEXTTYPE:<CTRLD><HOME>f<CTRLU>><WAITWIN2:000010:000000:Find><TEXTTYPE:View full details><REP3:01:000000:000001:99999:1:01:><TEXTTYPE:<ENTER>><IFOTH:03:1:Notepad><TEXTTYPE:<ESC><ESC><CONTROL><END><ENTER>%N1%><MSTOP><ENDIF><NMVAR:08:01:0:0000001:0:0000000><ENDREP> -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
kay_dee Posted November 7, 2007 Author Report Share Posted November 7, 2007 Well, I guess that's the command I didn't get right. I was trying to have the macro repeat until it matched the window title. I tried out your script and it gave me a different result each of the 5 times I ran it Your logic is incorrect in several ways. For example, you have asked the macro to repeat the loop zero times! And where are you viewing your result? I'm no expert myself, so there are probably smarter ways, but the following drastically edited version works OK: <SPKEY:0010><IVAR2:01:01:0><LAUNCHNO3:0:0130Untitled - Notepad<LAUNCH:c:\windows\notepad.exe><CLIPP><TEXTTYPE:<CTRLD><HOME>f<CTRLU>><WAITWIN2:000010:000000:Find><TEXTTYPE:View full details><REP3:08:000001:000002:0002:0:01:999999><TEXTTYPE:<ENTER>><IFOTH:03:1:Notepad><TBOX4:T:4:CenterCenter000278000200:000:ResultThe string 'View full details' appears %N1% times in this file.><TEXTTYPE:<ESC><ESC>><REM2:Close the Find dialog (keeping Notepad open) and STOP the macro at once.><MSTOP><ENDIF><NMVAR:08:01:0:0000001:0:0000000><ENDREP> -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
terrypin Posted November 7, 2007 Report Share Posted November 7, 2007 Works fine here. What procedure are you following? What is on your clipboard? Are you ensuring you don't change it in between trials? With the following copied into my clipboard View full details aaaaaaaa bbbbbbbbbbbbb ccccccccccc xxxxxxxxxxView full detailsyyyyyyyyyyyyy I run the macro (using F9 directly from the Scripting Editor) and I get a Notepad file with that text followed by the correct result, 2. I close Notepad, and repeat the exercise, copying the text into my clipboard again from another permanent source. Result is again identical. -- Terry, East Grinstead, UK Quote Link to comment Share on other sites More sharing options...
kay_dee Posted November 7, 2007 Author Report Share Posted November 7, 2007 Yes, I did the same with this text too and it first gave me 6 then 5 then 8! I did not change anything - copied the script directly from your reply. Quote Link to comment Share on other sites More sharing options...
kay_dee Posted November 7, 2007 Author Report Share Posted November 7, 2007 Timing issue. I added a delay and it is working fine now Thanks for your help! Quote Link to comment Share on other sites More sharing options...
Cory Posted November 13, 2007 Report Share Posted November 13, 2007 I recently found a really good way to do this so I added it to my webpage here. Quote Link to comment Share on other sites More sharing options...
kay_dee Posted November 14, 2007 Author Report Share Posted November 14, 2007 Cory: Well, I ran into lots of problems trying to customize this script, so I came back to the forum today to look for other solutions. I saw your post at the top, checked out your macro, and WOW! I did modify your script a little because I didn't want the prompt box (and it didn't allow CR either). Many thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.