Jump to content
Macro Express Forums

Incrementing Numbers


rhadin
 Share

Recommended Posts

I am struggling with a macro in 3.5e and hope someone can help me. Here is what I want the macro to do in MS Word 2003:

 

1. insert a number (beginning at 1) at the cursor location in doc 1

2. go to doc 2 and do the following

3. search for the bookmark named stop

4. at the bookmark type open a menu of choices of text to type at that location

5. when the choice is made, type AQ

6. immediately following the Q insert the same number as in step 1 above

7. type the balance of the text

8. add a paragraph return (so that the cursor is at the beginning of the next line) and insert at this location the bookmark called stop

9. go to doc 1 where the number inserted in step 1 is found

10. add 1 to that number and save it to the macro so that the next time the macro is run the number inserted in steps 1 and 6 is 1 more than it was the last time the macro was run.

 

However, although the numbering will increase in doc 1 until until I am done working in doc 1, when I open doc 3 and its companion doc 4, the numbering need to start at 1 again. Consequently, I need an easy way to reset the starting number to 1.

 

Although I have used the terms doc 1, doc 2, doc 3, and doc 4, the actual documents are paired and will always have the following in their names so that the <Activate:> command can be used and set once.

 

Docs 1 and 3 would be the main text documents and always have .EDT.doc in the name. The companion docs, 2 and 4, are for questions about content in the other docs and always have _queries.doc in the name.

 

I have not had much trouble with most of the coding, but I can't figure out how to write the code to accomplish 1, 6, and 10. What happens is that the number remains the same, that is, it remains the starting number (which is 1). It seems to me that the best way to store the number is in a separate "macro" that is called, but I'm open to any and all suggestions.

 

Thanks.

 

Rich Adin

rhadin@editorsource.com

Link to comment
Share on other sites

Each time a macro runs the variables are reset to their default values (integers are set to 0) but it is easy to save variables so you can increment it each time a macro runs. Variables can be stored in memory, in an .INI file, in environment variables, in a text file or in the registry.

 

Unless you store the counter in the registry, you will have to convert it to a string before saving it and convert it from a string to an integer after reading it. Here is a sample that uses the registry.

// Set a default value for the counter and try to read it from the registry
Variable Set Integer %N1% to 1
Read Registry Integer: "SampleNumber"

// Do your macro

// Increment the counter and save it for later
Variable Modify Integer: Inc (%N1%)
Write Registry Integer: "SampleNumber"


// Reset the counter and save it to the registry
Variable Set Integer %N1% to 1
Write Registry Integer: "SampleNumber"

Here are some of the macro commands you can use if you do not want to save the integer value in the registry.

// Save / restore all text variables (%Tx%)
Variable Save Text Variables
Variable Restore Text Variables

// Save / restore all variables
Variable Save All Variables
Variable Restore All Variables

// Save / restore a single variable using an .INI file
Variable Modify String: Save %T1% to INI File
Variable Set String %T1% from INI File

// Save / restore a single variable using the environment variables
Variable Modify String: Save %T1% to Environment Variable
Variable Set String %T1% from Environment Variable

// Save / restore a single variable using a text file
Variable Modify String: Save %T1% to Text File
Variable Set String %T1% from File: "T1"

// Convert an integer to a string and a string to an integer
Variable Modify Integer: Convert %N1% to text string %T1%
Variable Modify String: Convert %T1% to integer %N1%

Link to comment
Share on other sites

Thanks, Kevin.

 

I'm not quite sure what to do with the samples you sent. What I mean is, how to incorporate the code into my macro. Part of the problem is that I use Direct Editor and what you provided doesn't fit the schema of DE. I've tried to use Script Editor but have found myself confused by it. I find it easier to follow entries in DE.

 

In looking at the choices, I suspect that I would use the .ini file method because it would be easier to manually reset the number back to 1. If I save to an .ini file, I'm not clear how I would do it.

 

Here is the macro I have:

________________________

 

[insert number here first]<ACTIVATE2:queries.doc><TEXTTYPE:<ALT>iks<ALT>g<ENTER>><TVAR2:01:01:A><MENU2:T:01:CenterCenter:Author QueriesSelect a query to enterBlank Query

Age-related terms

Confirm x-ref

Change per AJR style

. . . [additional options]

Cancel><IFVAR2:1:01:1:TA><TEXTTYPE:AQ:<SPACE>><PAUSE2:000300,000400Enter query and click resume><TEXTTYPE:<ENTER><ARROW DOWN><HOME><ALT>iks<ALT>a><ACTIVATE2:EDT.doc><ENDIF>[macro continues similarly]

____________________

 

How do I fit the .ini language in it? The [insert number here first] is the placeholder for where the number has to be inserted in the EDT document (or doc 1 in my prior e-mail). That number has to be repeated between the Q and the : at the beginning of each variable (e.g. if I choose the first option, Variable A, the number replaces the text [number] in the following: <TEXTTYPE:AQ[number]:<SPACE>). The macro will run once and the number needs to be incremented by 1. I might not run the macro again until tomorrow or after a reboot, at which time, unless I have reset it to 1 in the .ini file beforehand, it needs to insert the incremental number.

 

I'm also assuming that I can name the .ini file, for example, ARRS.ini and place it in the same directory as my MacroExpress keyboards. Is this correct or does it have to have a particular name and location?

 

I'm sorry to be asking what are probably simple things, but I can't quite grasp how to do it.

 

Rich

Link to comment
Share on other sites

Rich,

 

I will try to describe in words what you need to do.

 

First you need to understand the difference between a string variable such as %T1% and an integer variable such as %N1%. A string can contain alphabetic, numeric and punctuation characters. An integer only contains a number. The string representation of a number (%T1%) is not the same thing as the number itself (%N1%). In other words, if %T1% is equal to '2571' and %N1% equals 2571 they are not the same. %T1% contains the visual representation of '2571' but %N1% contains the actual numeric value of 2571.

 

Certain macro commands that save variables will only save string variables. To save a number, you have to convert the numeric value to a string.

 

At the top of your macro:

1. Set your integer variable that represents your counter to a default value. Do this in case the value has never been stored before.

2. Read the counter from a permanent place. I gave an example that uses the registry but you want to use an .INI file.

3. If you use an .INI file, you will be reading a string, not an integer. So, after reading, you will need to convert the string into an integer.

 

Further down in your macro:

1. Increment (add one to it) the integer variable that represents your counter.

2. Convert the integer variable to a string

3. Save the string to the .INI file.

Part of the problem is that I use Direct Editor and what you provided doesn't fit the schema of DE. I've tried to use Script Editor but have found myself confused by it. I find it easier to follow entries in DE.
The Scripting Editor shows each macro command in a form that should be easier, not more difficult, to read. However, I suppose it depends on what you are used to. When an example is given in the Direct Editor format, I copy and paste it into a macro and then view it in the Scripting Editor so I can understand it.
How do I fit the .ini language in it?
By ".ini language" do you mean a string? See my description of strings and integers above.
I'm also assuming that I can name the .ini file, for example, ARRS.ini and place it in the same directory as my MacroExpress keyboards. Is this correct or does it have to have a particular name and location?
You can name the .ini file anything you want and you can place it in any folder you desire. Your login name must have the access privileges to read and write to the file and folder, however. (For example, some users, when they log on, cannot write to files in the folders underneath c:\Program Files.)

 

For more information about saving/reading variables to/from an .ini file read the INI Files and Variables topic in the help. You should also review the Variables Overview help topic. These are available on the web at the links above or within the help inside Macro Express itself. To view the help when the Macro Express Editor is running you can click Help and then Macro Express help.

Link to comment
Share on other sites

Kevin,

 

I meant to write yesterday but got tied up in work and simply never got to it. Thanks again for the detailed explanation. By using the information in both of your responses, I was able to write my macro with the incrementing number portion included. It took a couple of attempts and about 30 minutes of time to get it figured out, but without your information I had been unable to do it even after several hours of trying.

 

What I did do, however, was add a companion macro that I use to reset the counter in the .ini file to 1. Sometimes I work on a document for several days, necessitating the macro to continue incrementing from the number I last used the day before. By having a companion macro to reset the number to 1, I can continue incrementing until I need to start over and I can accomplish the start over easily by running the companion macro.

 

I appreciate the help.

 

Another question, if I might: Quite sometime ago (a couple of years, perhaps; it's version 3.4.01) I purchased the PGM add-on functions for ME. I have never used the functions. Should I consider redoing the macros using the PGM functions?

 

Rich

Link to comment
Share on other sites

Richard -

 

The PGM Functions Library contains advanced variable save and restore functions, however, they are meant to be used during a single run session of set of macros.

 

Kevin's idea of saving the last number used in an INI file is your best bet. And don't forget that an INI file is a text file, and like any other text file it can be edited. So, if you ever need to change the last number used you can do so.

Link to comment
Share on other sites

Thanks, Joe, for the information on PGM. As you can probably tell, I bought the PGM library and the source code (bought them in 12/04), but have yet to use them. I also bought your book when it came out. That I have used (or tried to, depending on my success :) ).

 

The ini file is working great for just the reason you mention (plus I'm uncomfortable playing with the Registry) -- especially as a true novice. It is especially easy with the ME macro to reset the variable to 1. Now if only the rest of my life were so easy to conquer :) .

 

Thanks for the help.

 

Rich

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...
 Share

×
×
  • Create New...