OldMacroDonald Posted September 7, 2023 Report Share Posted September 7, 2023 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted September 7, 2023 Report Share Posted September 7, 2023 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. Quote Link to comment Share on other sites More sharing options...
acantor Posted September 7, 2023 Report Share Posted September 7, 2023 I think I've scripted macros that do something like that. I'll check and report back. Quote Link to comment Share on other sites More sharing options...
acantor Posted September 7, 2023 Report Share Posted September 7, 2023 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"/> Quote Link to comment Share on other sites More sharing options...
OldMacroDonald Posted September 11, 2023 Author Report Share Posted September 11, 2023 Awesome, thank you! Do you have that one as a macro file? I tried pasting it into the direct editor and it was changing everything to text type. Quote Link to comment Share on other sites More sharing options...
Cory Posted September 11, 2023 Report Share Posted September 11, 2023 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted September 11, 2023 Report Share Posted September 11, 2023 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. 🙂 Quote Link to comment Share on other sites More sharing options...
Samrae Posted September 11, 2023 Report Share Posted September 11, 2023 I was able to copy the macro. I highlighted from <VARIABLE RESTORE Option="\x02"/> through <VARIABLE SAVE Option="\x02"/> Pressed Ctrl+c and pasted into the Script Editor. I also tried pasting into the Direct Editor. Both worked for me. Quote Link to comment Share on other sites More sharing options...
acantor Posted September 11, 2023 Report Share Posted September 11, 2023 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! Quote Link to comment Share on other sites More sharing options...
OldMacroDonald Posted September 11, 2023 Author Report Share Posted September 11, 2023 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted September 11, 2023 Report Share Posted September 11, 2023 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. Quote Link to comment Share on other sites More sharing options...
OldMacroDonald Posted September 11, 2023 Author Report Share Posted September 11, 2023 I'm using MacroExpress 3 so I should have posted my topic in that forum, sorry to all. I downloaded a trial of ME6 on another computer and I was able to paste the code into the direct editor there, though I'll need to figure out how to convert it to be compatible in ME3 since I won't be able to use the new version. Quote Link to comment Share on other sites More sharing options...
Cory Posted September 12, 2023 Report Share Posted September 12, 2023 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. Quote Link to comment Share on other sites More sharing options...
acantor Posted September 12, 2023 Report Share Posted September 12, 2023 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. Quote Link to comment Share on other sites More sharing options...
OldMacroDonald Posted September 12, 2023 Author Report Share Posted September 12, 2023 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% Quote Link to comment Share on other sites More sharing options...
acantor Posted September 12, 2023 Report Share Posted September 12, 2023 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. Quote Link to comment Share on other sites More sharing options...
Cory Posted September 12, 2023 Report Share Posted September 12, 2023 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. Quote Link to comment Share on other sites More sharing options...
acantor Posted September 13, 2023 Report Share Posted September 13, 2023 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! Quote Link to comment Share on other sites More sharing options...
Cory Posted September 13, 2023 Report Share Posted September 13, 2023 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 🖖 Quote Link to comment Share on other sites More sharing options...
acantor Posted September 13, 2023 Report Share Posted September 13, 2023 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. Quote Link to comment Share on other sites More sharing options...
OldMacroDonald Posted September 13, 2023 Author Report Share Posted September 13, 2023 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> Quote Link to comment Share on other sites More sharing options...
acantor Posted September 13, 2023 Report Share Posted September 13, 2023 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%]% Quote Link to comment Share on other sites More sharing options...
rberq Posted September 13, 2023 Report Share Posted September 13, 2023 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" Quote Link to comment Share on other sites More sharing options...
acantor Posted September 13, 2023 Report Share Posted September 13, 2023 Because of the complexities of nested variables in Version 3, you could do this instead: If Variable %N1% = 1 Text Type: Test 1 End If If Variable %N1% = 2 Text Type: Test 2 End If [etcetra] If Variable %N1% = 0 OR If Variable %N1% = 4 Text Type: Test 1 End If Quote Link to comment Share on other sites More sharing options...
OldMacroDonald Posted September 13, 2023 Author Report Share Posted September 13, 2023 Thank you! The nesting variables may not work in ME3, based off the number of different combinations I tried. This solution worked! I just had to add a restore variable line at the start and save variables at the end Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.