help with notepad's replace

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
bhogue
Newbie
Posts: 9
Joined: Fri Jul 08, 2005 5:25 pm

help with notepad's replace

Post by bhogue » Fri Jul 08, 2005 5:40 pm

I need some help. I want to use Notepad to replace some bad characters in a TXT file. The script to open the file works. I cannot get the Replace window to popup. I use the recorder to capture this information. When I paste those lines into my script, they do not work!

CTRL-H is the keystroke to bring up the Replace window. Here is the pasted code

Press CTRL
Wait>0.45
Send>h
WaitWindowOpen>Replace
MoveWindow>Replace,484,471
ResizeWindow>Replace,351,185
Wait>1.62
Release CTRL

I am not running Citrix. I tried the SK_DELAY=1 anyway. I tried LCTRL instead of CTRL. All yield the same result. I have a MessageModal immediately before the above script. It appears. I have a MessageModal immediately after this script. It never appears.

Can someone point me in the correct direction?

-brian

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Jul 08, 2005 6:03 pm

Control H doesn't work for me either, I don't know why. Since I assume you need to get the job done I'll post this quickie work around code using ALT E R instead.

Code: Select all

Run>notepad.exe c:\mydir\myfile.txt
SetFocus>myfile*
Press ALT
Send>E
Release Alt
Send>R
Send>This
Press TAB
Send>That
Press TAB
Press ALT
Send>A
Release ALT
Press ESC

bhogue
Newbie
Posts: 9
Joined: Fri Jul 08, 2005 5:25 pm

help with notepad's replace

Post by bhogue » Fri Jul 08, 2005 8:04 pm

Great idea!

Unfortunately it does not work either :-(

I added these three records to the input file to test your suggestion

this
this1
this2

I expected to see

that
that1
that2

These test records did not change. I still need help.

-brian[/quote]

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Jul 08, 2005 8:27 pm

I don't know what to tell you, it works for me. Are you getting any error messages? What version of windows are you using?

Before:

Image

After:

Image[/url]

bhogue
Newbie
Posts: 9
Joined: Fri Jul 08, 2005 5:25 pm

Post by bhogue » Mon Jul 11, 2005 8:07 pm

Thanks for that answer. I started from your sample code ... which worked for me. I am unable to get my code working. So I am building from your sample.

-brian

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Jul 12, 2005 4:11 am

Brian,

This doesn't answer your original question but:
Would you be willing to try modifying your text file outside of notepad? Macro Scheduler does a dandy job with text file editing all by itself. It is very fast and accurate. You can easily make changes using the readfile function to import the text file into Macro Scheduler then by using the stringreplace function to make the modification(s). Lastly use writeln to write the edited text back out to a file.

This sample will create a new file. This is a safe way to perform this task but if you want, you can use the filedelete function after performing the readfile function and then write the file back to the original name and location.

Starting with a text file called C:\test.txt that contains:

this1
this2
this3

run this script

Readfile>c:\test.txt,file
StringReplace>file,this1,that1,newfile
StringReplace>newfile,this2,that2,file
StringReplace>file,this3,that3,newfile
WriteLn>c:\newtest.txt,wresult,%newfile%

And end up with a text file called C:\newtest.txt that contains:

that1
that2
that3

Hope this was helpful,
Dick

bhogue
Newbie
Posts: 9
Joined: Fri Jul 08, 2005 5:25 pm

Post by bhogue » Tue Jul 12, 2005 8:33 pm

JRL -

Thanks for the tip. I did not see that StringReplace. I agree that works. I chose this product because it could run other programs on my desktop, like Notepad and Access, in addition to more typical programming. If I cannot get the simple Notepad steps working, I expect a great deal of difficulty with Access. Finally, I will need to add some steps with Internet Explorer. At this stage, I need to accomplish something that sets up the rest of the project ... or go to a product that will help me complete this small project.

-brian

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Tue Jul 12, 2005 11:04 pm

bhogue,

Please post your script so that we can tell you what is wrong with it. Two commands of utmost importance are WaitWindowOpen and SetFocus. So far the script code I have seen posted here has no WaitWindowOpen so after running Notepad no allowance is made for how long it takes to open before any keystrokes are sent to it. This will work:

//start notepad, wait for it to be open and ready and ensure it is focused
Run>notepad.exe c:\mydir\myfile.txt
WaitWindowOpen>- Notepad*
SetFocus>- Notepad*
//invoke the text replace dialog
Press ALT
Send>er
Release ALT
//send text to replace
Send>This
Press Tab
Send>That
//do alt-a for replace all
Press ALT
Send>a
Release ALT
Press Esc

Please read the scripting for beginners guide in the help file as it takes you through a notepad example and explains these key concepts. To re-cap

1. Almost always you will want a WaitWindowOpen after Running an app and before sending keystrokes to it.
2. Ensure you SetFocus the right window before sending keystrokes
3. Use lower case characters when sending alt, shift or ctrl key combinations.

As JRL says using notepad to replace text is overkill and cumbersome when you can just ReadFile and StringReplace. But notepad is a great example and good for learning how to do this stuff.

Please go through the beginners guide in the help file and you will be well on your way. Same principles will apply when you move on to automating MS Access.
MJT Net Support
[email protected]

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Tue Jul 12, 2005 11:15 pm

Thanks for the tips :D

Can you tell us why using CTRL H doesn't work?

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Post by CyberCitizen » Wed Jul 13, 2005 12:36 am

I Was After Something Similar In Regards To Replacing A Text String, However I Could Not Get It To Work So I Had It Do It In Notepad As Well.

Here Is My Script.


Label>Edit_File
Run Program>Notepad C:\tdqm_loader.js
WaitWindowOpen>Notepad*
Wait>1
Press Alt
Send Character/Text>e
Wait>1
Send Character/Text>r
Release Alt
Send Character/Text>{if(q71==eval(c1+"o"+d1+"e"+i))return true;}}return false;}
Press Tab
Send Character/Text>{if(q71==eval(c1+"o"+d1+"e"+i))return true;}}return true;}
Press Tab * 4
Send Character/Text>
Press Alt
Press F4
Release Alt
Wait>0.5
Press Alt
Press F4
Release Alt
Wait>1
Send Character/Text>
Goto>Exit


I Had To Do It This Was As The Text In The File Was Always Different. I Also Posted This Question In The MJTNet Forums However No One Was Able To Get It To Work.

This Works Now Anyway, So I Am Happy With This.

This Script Appears To Work When Pressing Ctrl H (Note Need To Send Lowercase h).


Run Program>Notepad C:\Windows\Win.ini
WaitWindowOpen>Notepad*
Wait>1
Press Ctrl
Send Character/Text>h
Release Ctrl
Goto>Exit

Label>Exit
FIREFIGHTER

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Wed Jul 13, 2005 4:20 am

Yep, that's it, using the keyboard Notepad doesn't care if caps lock is set but in a script the upper case H doesn't work.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Wed Jul 13, 2005 7:25 am

Always always always use lower case letters when signifying ALT,CTRL or SHIFT keystroke combinations. Uppercase can act as if Shift was also pressed. e.g. CTRL-H may be treated as Ctrl-Shift-h. You're sending a KEY not a character so always do Press CTRL Send>h Release CTRL.
MJT Net Support
[email protected]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts