Jump to content
Macro Express Forums

Pasting text from a rotating list of variables?


Recommended Posts

I would like to create a macro that would paste text from a set of predefined variables that would change after every time I used the macro. For example pressing the hotkey would paste "hello" then pressing it a second time would switch to the next variable in the list "goodbye" and so on. Would I create the list through Variable Set String for each text? After that, I'm clueless as to how to get it to keep track of what has been used and switch to the next variable in the list.

Link to comment
Share on other sites

You could make a text file for the list. I would prefer to use the registry though. When the macro runs do a Text File Process and get the desired row. Then you would get and save the index (pointer) in another file or, as I prefer to do, the registry. Each time it runs, increment it and save the new value. In the Text File Process, abort at the desired line using the pointer. 

Link to comment
Share on other sites

Variable Restore: Restore Integer Variables
 
// Here are the texts to display
Variable Set String %Text1% to "This is a test."
Variable Set String %Text2% to "This is a second test."
Variable Set String %Text3% to "This is a third test."
 
// There are only three texts, so adjust %Count% when it is out of range
If Variable %Count% Equals "0"
  Variable Set Integer %Count% to 1
End If
 
If Variable %Count% Equals "4"
  Variable Set Integer %Count% to 1
End If
 
// Get the text length so the text can be selected
Variable Set Integer %LenText1% to the length of variable %Text1%
Variable Set Integer %LenText2% to the length of variable %Text2%
Variable Set Integer %LenText3% to the length of variable %Text3%
 
// Type out a text...
Text Type (Simulate Keystrokes): %Text%Count%%
 
// ...and immediately select it via Shift + Left
Repeat Start (Repeat %LenText%Count%% times)
  Text Type (Simulate Keystrokes): <SHIFT><ARROW LEFT>
End Repeat
 
// Increment %Count%
Variable Modify Integer %Count%: Increment
 
// Preserve Integer variable (but won't survive a reboot)
Variable Save: Save Integer Variables


<VARIABLE RESTORE Option="\x02"/>
<COMMENT/>
<COMMENT Value="Here are the texts to display"/>
<VARIABLE SET STRING Option="\x00" Destination="%Text1%" Value="This is a test." NoEmbeddedVars="FALSE"/>
<VARIABLE SET STRING Option="\x00" Destination="%Text2%" Value="This is a second test." NoEmbeddedVars="FALSE"/>
<VARIABLE SET STRING Option="\x00" Destination="%Text3%" Value="This is a third test." NoEmbeddedVars="FALSE"/>
<COMMENT/>
<COMMENT Value="There are only three texts, so adjust %Count% when it is out of range"/>
<IF VARIABLE Variable="%Count%" Condition="\x00" Value="0" IgnoreCase="FALSE"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%Count%" Value="1"/>
<END IF/>
<COMMENT/>
<IF VARIABLE Variable="%Count%" Condition="\x00" Value="4" IgnoreCase="FALSE"/>
<VARIABLE SET INTEGER Option="\x00" Destination="%Count%" Value="1"/>
<END IF/>
<COMMENT/>
<COMMENT Value="Get the text length so the text can be selected"/>
<VARIABLE SET INTEGER Option="\x0D" Destination="%LenText1%" Text_Variable="%Text1%"/>
<VARIABLE SET INTEGER Option="\x0D" Destination="%LenText2%" Text_Variable="%Text2%"/>
<VARIABLE SET INTEGER Option="\x0D" Destination="%LenText3%" Text_Variable="%Text3%"/>
<COMMENT/>
<COMMENT Value="Type out a text..."/>
<TEXT TYPE Action="0" Text="%Text%Count%%"/>
<COMMENT/>
<COMMENT Value="...and immediately select it via Shift + Left"/>
<REPEAT START Start="1" Step="1" Count="%LenText%Count%%" Save="FALSE"/>
<TEXT TYPE Action="0" Text="<SHIFT><ARROW LEFT>"/>
<END REPEAT/>
<COMMENT/>
<COMMENT Value="Increment %Count%"/>
<VARIABLE MODIFY INTEGER Option="\x07" Destination="%Count%"/>
<COMMENT/>
<COMMENT Value="Preserve Integer variable (but won't survive a reboot)"/>
<VARIABLE SAVE Option="\x02"/>

 

Link to comment
Share on other sites

Weird. I omitted the first lines and the first clump of commands came in as one Text Type sommand. Something it doesn't think is valid in there. Acantor I suggest in cases like this you simple export the macro to a MEX file in cases like this. ALso it preserves the variable definitions. 

Link to comment
Share on other sites

OldMacroDonald I know it's nice to just have someone do it for you, but it's also worth trying to work though it yourself. You will learn more in most cases. 

But I'm weird. I'm more the "teach a man a fish" instead of the "give a man a fish" kind of forum member. 🙂

Link to comment
Share on other sites

I second Cory's suggestion: you'll learn more by working through it yourself. My script consists of fewer than 20 lines of code, so building your own version shouldn't take too long!

 

Another reason to start from scratch: my script probably doesn't do exactly what you need it to do. Maybe you want ten different texts instead of three. Maybe you don't need to select outputted texts.

 

And another reason: Scripts can be "fragile." They sometimes fail when least expected. I learned recently that my script fails when run in certain editors. You'll be better prepared to deal with "edge" conditions, which are almost inevitable, if you build on an example rather than import an example.

 

And a final reason: If I were writing this script today, I wouldn't use the same method. I'm fairly certain I would end up with code that's easier to understand, more efficient, and possibly easier to maintain.

 

Please share your version!

Link to comment
Share on other sites

I think the problem might be that my version of Macro express might be too old? I tried to recreate the script by using the scripting editor and the text for the commands looks very different in the direct editor. I'm guessing the lines like <VARIABLE SAVE Option="\x02"/> refer to the different settings available, but option 2 on the variable save menu might be different on my version of the program. 

This script uses a lot of commands I've never heard of before but hopefully gives me a starting point to try to figure out what they all do so I can try to recreate it.

Link to comment
Share on other sites

A lesson for today! 
There are two views for the editor, normal and direct. Select from the view menu. In your example if If one copies the display text, none of the useful settings will be transferred. If i paste that in, which MEP understands, you will see it displayed as the normal text of "Variable Save: Save Integer Variables". If I open the command, I'll see the correct option is selected. 

Often in the past when I'd post samples, I would post them as the command text and the direct so one could see both. 

 

YOu might want to do a few of the MEP tutorials to get a better feel for things. ISS has some good stuff on their website. 

Link to comment
Share on other sites

The version isn't important in this case. The basic concepts are the same. Off the top of my head the only thing you will need to compensate for are the variable limitations. Older ME has 4 immutable variable arrays and MEP has user defined variables. To me that feature alone was worth the upgrade, but that's up to you. 

Link to comment
Share on other sites

It's been so long since I used Macro Express 3 that I don't recall if all of the features of later versions are included. For example:

 

Variable Restore: Restore Integer Variables

 

This "Restore" instruction at the start of the script, and the corresponding "Save" command at the end, may or may not be available in Version 3. 

 

Macro Express 6 will convert Version 3 scripts to Version 6. But you can't go in the opposite direction.

 

When a script uses variables (as my script does), Version 3 is MUCH less convenient. The naming convention for variables in Version 3 is very constrained: %N[1]% in Version 3 can be %Counter% or %Value%... in other words, you can use easy-to-understand variable names in Version 6.

Link to comment
Share on other sites

I tried to program it as simply as possible with my limited knowledge of ME. I set my text string (T) variables then did an if variable set N back to 1 to correspond with the number of text strings I have. It then pastes the text variable T and modifies the N by adding 1. This method doesn't work because I thought I would be able to "nest" the variables by trying to paste %T%N1%% but that's not an option it seems. I need to come up with a way to cycle through %T1% through %T8%

Link to comment
Share on other sites

Share your code... maybe we can help sort out what's not working. My recollection is that square brackets are integral to Version 3 variable names: %N[1]% rather than %N1%.

 

Nested variable names in Version 3 were very messy... %T[%N[1]%]% or something like that. It can be done, but it's much easier with the modern version.

Link to comment
Share on other sites

If you are working in MEP I recommend making a simple macro to demonstrate, exporting it to an MEX file, and sharing it here. This will preserve variables and such. We can then comment better and make tweaks and post back.

If you're not looking for a MEP solution or to at least learn how to do it in MEP, then I I'm not willing to install ME and try to recall how things were done way back then. Sorry.

Also this shoudl be posted in the appropriate forum where acantor and others who use ME can help you better. 

Link to comment
Share on other sites

Quote

Also this shoudl be posted in the appropriate forum where acantor and others who use ME can help you better. 

 

Although the discussion on this forum has, for years, focused almost exclusively on Macro Express Pro, the forum continues to be called "Macro Express and Macro Express Pro." So this forum is appropriate for questions about the older product. The problem is that most of the "regulars" switched to the Pro version eons ago. We may need our memories refreshed!

Link to comment
Share on other sites

I apologize. My mistake. I didn't notice that they names and lineups of forums had changed. Mea culpa. Then it is I who should to the right thing and stop following and offering help in this thread. Saves me time too. 👍

BTW I've never agreed with ISS's confusing split in product versions and naming. 
On another note.... I have never understood why people would opt to spend dozens of hours on issues instead of just upgrading for a few bucks. Why make life more difficult? [rhetorical] I value my time more than that I guess. 

Live long and prosper 🖖

Link to comment
Share on other sites

Even if someone on the forum were to create a Macro Express Pro script that does what you want, you won't be able to run the script in Macro Express.

 

That's because the underlying code in the two versions is different. Fortunately, Macro Express Pro converts Macro Express scripts, but unfortunately, the opposite isn't true: Macro Express cannot convert Macro Express Pro scripts. 

 

So unless you update to the Pro edition, you must start from scratch. If you post your code of your non-working script, some of us may be able to spot what's wrong.

 

Cory's suggestion is spot-on: Start simple. Try making a script that works with two (or three) texts instead of eight.

Link to comment
Share on other sites

I would upgrade to the new version if I could, but this is on a work computer and it would be easier to go back to school and get a computer programming degree than to run the bureaucratic IT gauntlet of getting new software approved.

Here's a screenshot and the direct code for what I was trying to do. Hopefully it's on the right track, but it's for sure not working because I don't know if I'm able to use incremental variables for the T variables. I've tried a few different versions of %T%N1%% but no success.

 

 

<VARSR:07><TVAR2:01:01:text1><TVAR2:02:01:text2><TVAR2:03:01:text3><IFVAR2:2:01:1:4><IVAR2:01:01:1><ENDIF><TEXTTYPE:%T[%N[1]%]%><NMVAR:08:01:0:0000001:0:0000000>

macrosc.png

Link to comment
Share on other sites

I think you're very close.

 

The first time this macro is run, the value of %N1% is probably 0. Therefore, the macro types the value of %T0%, which has no value.

 

Add these lines after the lines that define T1, T2, etc.:

 

If Variable %N1% = 0

   Variable Set Integer %N1% to 1

End If

 

I'm not sure the Text Type instruction is right. If it isn't, try this:

 

Text Type: %T[%N1%]%

 

Link to comment
Share on other sites

Also: I see "Restore Integer Variables" at the beginning of your script.  Should there be a corresponding "Save Integer Variables" at the end?

 

Passing variable values in this way is handy, but a little bit risky.  A totally unrelated macro, running between two iterations of your macro, could potentially "save" an N1 value GREATER than 4, in which case your macro would continue to increment N1 more or less forever.  It would be safer to say

 

If Variable %N1% Is Greater Than or Equal To "4"

 

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...
×
×
  • Create New...