Jump to content
Macro Express Forums

repeat counter / modify integer


kay_dee
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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%>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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! :D

 

I did modify your script a little because I didn't want the prompt box (and it didn't allow CR either).

 

Many thanks! ^_^

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...