Moving the cursor

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
srhamy
Newbie
Posts: 9
Joined: Sun Nov 26, 2006 12:38 am

Moving the cursor

Post by srhamy » Sun Nov 26, 2006 12:53 am

I wanted a little bit of guidance how I would most cleanly do the following. Within notepad move to the next occurrence of "[]" (a tabstop) and delete it leaving the cursor at that position. I know I can use the menus/CTRL-R for replace but I would rather not deal with the flashing up of the find/replace window. I thought about copying window text to a variable, finding the position, but I really don't want to send X number of RARROW presses either.

I guess my question is: How do I move the cursor to a specific postion within a text file? :roll:
Scott Rhamy

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

Post by JRL » Sun Nov 26, 2006 2:21 am

Hi Scott,
As far as I know, when you're working within an application, be it Notepad or anything else, you're stuck with using keystrokes, mousemoves and menu calls available to the application.

That said, I'd like to ask you a question. Why are you dealing with Notepad? Anything that Notepad can do you can do transparently by manipulating the text through Macro Scheduler. Any time I can avoid using an application other than Macro Scheduler to accomplish a task I do it.

The text exists somewhere (file, clipboard, webpage, etc.) before you put it into Notepad. If you can get it to Notepad you can also get it to Macro Scheduler by using the ReadLn> or ReadFile> or possibly GetClipBoard> functions. After you have the text captured you can manipulate it using any of the string handling commands.

For example if you are trying to replace "[]" with "sometext" you could:

Readfile>YourFile,filetext
StringReplace>%filetext%,[],sometext,newtext
WriteLn>NewFile,wresult,%newtext%


Let us know what you want to do. Hope this was helpful
Dick

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sun Nov 26, 2006 2:31 am

It does not sound like you just want to delete the Tab with something else.

If you wanted to that, you might be able to do that with Macro Scheduler's StringReplace() or use the VB Replace() function.

But doin either of those will only remove the Tabs, it will not leave you in a text editor with the cursor at the point where a Tab was removed.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

srhamy
Newbie
Posts: 9
Joined: Sun Nov 26, 2006 12:38 am

Ongoing...

Post by srhamy » Sun Nov 26, 2006 2:44 am

I am using notepad (or something similar) that would include a basic template with [] marking tabstops. I would like to sequentially hotkey to the tabstop positions deleting them and allowing for variable text input. I will look into the vbreplace function, but as you said that wouldn't move the cursor so it probaly wouldn't work alone.

Thanks for the help though....
Scott Rhamy

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sun Nov 26, 2006 4:28 am

Let us know exactly what program you are using. "something similar" to Notepad probably is not exactly identical regarding its features and navigation.

It sounds like you have a text document that you want to browse through t a Tab Stop and insert some variable text at that point. Then you want to go to the next Tab, stop and insert text again, then repeat that process multiple times, is that correct?

So you probably want some type of hotkey to use after you have entered text to move to the next position, stop. You will enter text, then press hotkey again. Is that a good description?

Again, what program and version are you planning on doing this with?

Are you committed to that program or are you open to an alternative program that might be better suited to the task?

What file type/format is the original file in before the editing?
What file type/format must the file be saved in when done?
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

srhamy
Newbie
Posts: 9
Joined: Sun Nov 26, 2006 12:38 am

...

Post by srhamy » Sun Nov 26, 2006 4:58 am

I'll use wordpad, but I am not married to using that program, nor any particular format (RTF would be preferable to TXT though). The description above is pretty accurate for what I wish to do. To be clear after I reach/clear a tabstop marker "[]", I will manually enter text, and then hotkey to the next tabstop position.
Scott Rhamy

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

Post by JRL » Sun Nov 26, 2006 6:14 am

I understand what you have asked for... and this isn't it. Instead this is an example of how I would prefer to do this task using Macro Scheduler. It might look ugly with an RTF file but I think it would still work.

The first input will ask for a file to work from, the second input will ask for the text to be replaced. For a Tab character type in %TAB%. The dialog should show the text prior to the text or character to be replaced, then a blank edit field to type in the text to replace your character and finally the text that follows the character or text you are replacing.

Ths script will write the result to a file C:\NewFile.txt unless you click the "X" on the dialog.

Hopefully someone will find this useful,
Dick

Code: Select all

Input>YourFile,Get text file
Input>RepText,Text to be replaced

Dialog>Dialog1
   Caption=Text Replacement Dialog
   Width=448
   Height=360
   Top=CENTER
   Left=CENTER
   Label=Text replacement Text,160,120
   Edit=msEdit1,16,136,401,
   Label=Pre Replacement Text,160,8
   Memo=msMemo1,16,24,401,89,
   Label=Post Replacement Text,160,168
   Memo=msMemo2,16,184,401,89,
   Button=Ok,176,296,75,25,3
EndDialog>Dialog1

Show>dialog1
Closedialog>dialog1

Readfile>YourFile,filetext
Separate>filetext,%RepText%,var
Let>cnt=0
Let>NewText=

Repeat>cnt
  add>cnt,1
  Let>next=%cnt%+1
  If>%cnt%=%var_count%,done
  Let>value1=var_%cnt%
  Let>value2=var_%next%
  Let>dialog1.msmemo1=%value1%
  Let>dialog1.msmemo2=%value2%
  RDA>dialog1
  Show>dialog1,r1
  If>r1=3,process
  If>r1=2,quit
  Goto>notdone
  Label>done
    Concat>NewText,%value2%
  Label>notdone
Until>cnt=var_count

SRT>process
  Concat>NewText,%value1%%dialog1.msedit1%
  If>%cnt%=%var_count%
    Concat>NewText,%value2%
  EndIf
  Let>dialog1.msedit1=
  Show>dialog1
  Press TAB
  CloseDialog>dialog1
END>process


WriteLn>C:\NewFile.txt,wresult,%NewText%

Label>quit

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sun Nov 26, 2006 6:40 am

No need for Macro Scheduler for this one......
If you use WordPad, you can use the normal F3 hot key once you have defined it. But this will allow you to go to each Tab[], and enter new text at each position, each text entry can be different if you desire.

Go to the beginning of your document.
Press CTL-F to open the Find window.
Enter the [] you are looking for (see Note below).
Click on Find Next to go to []
Click on Cancel to close the window.
Press delete to remove the [] and type your new text.
Now just press F3 to move to the next [], Delete, enter new text.
Repeat the F3, Delete, enter new text sequence as necessary.
There will be no flashing of the Find Window when you use the F3 hotkey.

NOTE: Although you cannot see the Tab character, you can go to the beginning of a Tab space on a line, select the Tab Space (hold the Shift key and press the Right Arrow) and copy the wide blue selection to the clipboard with CTL-C. Now when you first open the Find Window, clear out the existing value and paste the Tab Space into the Find what field like any other character. If done properly you will see a wide blue Tab Space.

------------------
Edited Note. This was written while JRL's posting was made. So I did not have the benefit of seeing his approach using Macro Scheduler.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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