Using Text String Variables

 

Below is an example of using Text String Variables. There are hundreds, even thousands of uses for Text String Variables. This example provides an idea of how they can be used and manipulated.

 

This macro, when completed, fixes typing transposition errors such as "adn" or "teh" instead of "and" or "the". Just place the cursor between the two transposed letters and press the assigned hot key to correct the typing error.

 

 


 

 

Setting up the Macro
 

a.From the Macro Express - Explorer menu click on Macro > New Macro to open a Create New Macro window.

b.The Initial Activation defaults to HotKey.

c.Click on the HotKey edit box to place the cursor there. 

d.Hold down the F4 key and release it.

e.F4 is placed in the edit box and is the hot key assigned to activate the macro.

f.Enter Fix Transposed Letters in the Nickname field and click OK to open the Script Editor.

g.Click on the Scope tab and make sure that the macro scope is set to global.

h.Click on the Script tab to start building the macro.

 

 

Building the Macro in the Script Editor


Step 1 -  Place a Comment (instructions) at the beginning of the macro.
 

a.Expand the Macro Control list of commands and double click on the Comment command.

b.Type "Place cursor between the transposed letters" (without the quotes) in the Comments Text edit field.

c.Click OK to save the entry.

 

The text is displayed in bold blue font in the Script Editor. The Comment line does not do anything in the script. It is just a reminder for later of how to use the macro.
 

 

Step 2 - Highlight the two transposed letters
 

a.Expand the Keyboard category and double click on the Text Type command.

b.Click on Arrow Left from the list of options in the yellow area of this window.

c.Then click on Shift Down, Arrow Right, Arrow Right and Shift Up.

d.Click OK to save and return to the Script Editor.

 

The entire entry should look like the following:  <ARROW LEFT><SHIFTD><ARROW RIGHT><ARROW RIGHT><SHIFTU>. This step highlights the two transposed characters.


 

Step 3 - Cut the highlighted text and copy to the clipboard
 

a.Expand the Clipboard category of commands

b.Double click on Clipboard Cut to insert the clipboard cut command as the next item in the script.

 

 

Step 4 - Save the clipboard contents to a text string variable.
 

a.Expand the Variable category of commands.

b.Double click on Variable Set String to open the Variable Set String window.

c.Select the Set Value from Clipboard option from the drop down menu.

d.Enter %T[1]% in the Destination Variable field and click OK to save.

 

 

Step 5 - Save each of the two transposed letters to individual text string variables
 

Copy the first letter of the variable T[1] and save it to variable T[2]. 
 

a.Expand the Variable category of commands and double click on the Variable Modify String command.

b.Select Copy Part of Text from the drop down list.

c.Enter %T[2]% in the Text Variable field and enter %T[1]% the Variable to copy from field.

d.Enter the number "1" (without the quotations) in the Starting Position field.

e.In the Number of Characters to Copy field enter the number "1" (without the quotations).

f.Click OK to save.

 

Copy the second letter of variable T[1] and save it to variable T[3].
 

a.Expand the Variable category of commands and double click on the Variable Modify String command.

b.Select Copy Part of Text from the drop down list.

c.Enter %T[3]% in the Text Variable field and enter %T[1]% in the Variable to copy from field.

d.Enter the number "2" (without the quotations) in the Starting Position field.

e.In the Number of Characters to Copy field enter the number "1" (without the quotations).

f.Click OK to save.


 

Step 6 - Play back the text in the correct order 
 

a.Expand the Keyboard category and double click on the Text Type command.

b.Type the following into the Keystrokes edit field: %T[3]%%T[2]%.

c.Click OK to save and return to the Script Editor.

 

This types out the second letter of the transposed text first, reversing the order and correcting the typing error.


 

Step 7 - Save the macro
 

a.Click on File > Save to save the macro.

 

 

Macro Script

The macro script should look like what is displayed below. If the macro doesn't look like this, arrange the commands so that they are in the following order by using the Up and Down arrows on the right hand side of the Script Editor.

 

 

// Place cursor between transposed letters.

Text Type (Simulate Keystrokes): <ARROW LEFT><SHIFTD><ARROW RIGHT><ARROW RIGHT><SHIFTU>

Clipboard Cut

Variable Set String %T[1]% from the clipboard contents

Variable Modify String %T[2]% to a substring in %T[1]% starting at 1 and 1 characters long

Variable Modify String %T[3]% to a substring in %T[1]% starting at 2 and 1 characters long

Text Type (Simulate Keystrokes): %T[3]%%T[2]%

 

 

Testing the macro

To test the macro, run the notepad program. (Depending on your version of Windows, click on the Windows Start button, enter notepad in the Search field and press enter. Or right click on the Windows Start button, select Run, enter notepad and click OK.)

 

Type the following text into notepad - Tihs is a tset. (Include the typing errors.)

 

Insert the cursor between the "i" and "h" in the word "Tihs". Press the F4 key to play back the macro. The letters are reversed to correct the spelling to "This". Try the same thing with the misspelled word "tset".

 

 

Note: If assigning original names to variables, rather than using T[1], D[1], etc., then the following characters are not allowed in the variable name:  [ ] < > , . - + = \ | / * %