Jump to content
Macro Express Forums

"Variable Modify Integer-Increment" possible outside of a repeat loop?


Recommended Posts



I've been using the "Variable Modify Integer-Increment" in a repeat loop to have the N1 variable increment +1 on every repeat within the macro execution. My question is this. Is there a way to have an increment function WITHOUT the repeat loop... ie. make it so every time a macro -with no repeat loop-is executed, a variable (N1) within the macro would increment by 1?


I want to create a macro where every time I run it, n1 increments by +1 and where this updated n1 value would be retained for the next time I execute the macro during the session.


I hope this was clear. Thanks

Link to comment
Share on other sites

It's not that easy. When a macro starts to run, all variables are cleared. To carry over a value you have to store the variable somewhere that will survive restarts of Macro Express and reboots of Windows. The most straightforward is probably an INI file.


Build the INI file manually with a text editor. Then each time the macro runs

Variable Set String [from INI file]

Variable Modify String [convert to integer]

Variable Modify Integer [increment]

Variable Modify Integer [convert to string]

Variable Modify String [save to INI file]


You could store the string in the Windows registry. My preference (prejudice?) is to stay away from the registry.


P.S. I just noticed you said you want to retain the count "during the session". In that case, you can store the string in an environment variable. The environment variable can be created on the fly with whatever name you choose to give it.

Link to comment
Share on other sites

You could store the string in the Windows registry. My preference (prejudice?) is to stay away from the registry.

This is precisely what the registry is ideal for. If you create yourself a key in the registry under HKEY_CURRENT_USER, e.g. MyKey, then you're as likely to damage your registry as you are to reformat your disk by accident - i.e. hardly likely at all.

Link to comment
Share on other sites

When Macro Express is installed the macro file 'samples.mex' is installed in the same folder as the Macro Express program files (e.g. c:\Program Files\Macro Express3). This macro file contains a macro titled 'Counter_From_Run_To_Run' that demonstrates what you are asking about.


In order to run properly, Macro Express must have full access rights (Read/Write/Create/Modify) to the macro file and the folder it is in. If you are using Windows 7 or Windows Vista or if you are running a prior version of Windows with a 'limited' user account, you should copy samples.mex to a folder where you have full access. Your 'My Documents' or 'Documents' folder will work.


You may also download samples.mex from our Sample Macros web page.

Link to comment
Share on other sites

Storing variables seems to be a subject for discussion every time it comes up. Here's my read on it.


Unless you are aware of all implications, you should steer clear of the registry. It's a central part of Windows and should not be used as a general dumping ground. In ME it's easy to use. Fine for specific items of data (as in your macro) and if you know what you are doing. The ME Help is excellent on Registry operations and includes a warning highlighted in red.


You can use ini or text files for storing data, both are simple text files. Ini are more organized allowing you to pick out specific items easier. You can create both in advance or if you type the path in the (Variable Modify String) Save to Text File or Save to Ini dialogs, ME will create the file for you. Ini and txt files can be opened at any time with any text editor. By default that would be Notepad. For one item I would use a text file (either way not going to save huge kB). You will have to convert the text to an integer and vice versa.


The other aspect I like about txt files is that if you are running a long macro that writes/appends to file, you can open the text file at any time and read the content as it accumulates.

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.

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.

  • Create New...