Specific Numbering Requirement

  • Thread starter Manish Mukherjee
  • Start date
M

Manish Mukherjee

All,
I want to create a MS-WORD dcoument of the following format:

req-1 This is statement 1
req-2 This is statement 2
req-3 This is statement 3

The key is:
1. These numbers must be assigned automatically (by use of a macro or
otherwise). When a statement is inserted and a predefined paragraph style is
applied for it, the line should transform into:

req-pend this is statement 4
Once the user saves the document, the document should automatically change
this line to:

req-4 this is statement 4.

2. If I remove req-2, the numbering for req-3 should NOT change
3. If I insert another line after req-3, after I had deleted req-2, it
should be inserted as req-4

The basic idea is that once a statement is added in and a number assigned to
it (e.g. req-2), this number should never be reused for the life of this
document.

I understand that I could use document variables to achieve this. Can anyone
point me to an example or give me some ideas.

Thanks,
- Manish M
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Manish:

This sounds to me like you're creating software requirements specifications
:)

Yes, you can indeed to it with document variables and (quite a lot...) of
supporting VBA code.

Rational Requisite Pro uses bookmarks, macros, and a database to achieve the
result.

Since you are in a software development team, grab one of the coders and ask
them to run it up for you. Or buy a copy of ReqPro. Or ping me or one of
the others by email and we can negotiate a fee for this. I am afraid your
precise requirement represents more coding than most of us would be willing
to do without charge.

I would probably approach the task by using one of the fields that is not
used for anything else in the document. I would probably choose the 'TC'
field, since Word automatically expects lots of them, and they can contain
text, and the text does not have to be unique.

I would create a macro that added a paragraph, set the paragraph to your
chosen Style, and added a TC field at the front with the text "req-pend"

I would create another macro that intercepted the Document.OnSave event. It
would then enumerate the Fields collection, and evaluate the text string
within each. The macro would need to parse right after the string 'req-'
and retrieve the integer it found there, loading all of the integers into an
array.

It would then need to sort the array (you need a WordBasic command for that,
VBA can't sort arrays). Look for the highest integer and set it into an
integer variable.

Then run through the TC fields collection again, take the first "pend" field
you find, change "pend" to the next highest integer, and so on, until you
reach the end of the collection.

Then allow the Save to complete.

Such a design is slow but quite robust. Of course, you would not need to
evaluate the entire collection if you stored the highest number in use in a
Document Variable. But if you did that and someone forgot to run the macro,
your macros would be unable to recover.

You might gain speed by using a hybrid design: using Bookmark fields for the
confirmed requirements and some other field for the Pending requirements.
Bookmark fields must have unique names, but they're stable and the
collection enumerates rapidly.

Hope this helps


All,
I want to create a MS-WORD dcoument of the following format:

req-1 This is statement 1
req-2 This is statement 2
req-3 This is statement 3

The key is:
1. These numbers must be assigned automatically (by use of a macro or
otherwise). When a statement is inserted and a predefined paragraph style is
applied for it, the line should transform into:

req-pend this is statement 4
Once the user saves the document, the document should automatically change
this line to:

req-4 this is statement 4.

2. If I remove req-2, the numbering for req-3 should NOT change
3. If I insert another line after req-3, after I had deleted req-2, it
should be inserted as req-4

The basic idea is that once a statement is added in and a number assigned to
it (e.g. req-2), this number should never be reused for the life of this
document.

I understand that I could use document variables to achieve this. Can anyone
point me to an example or give me some ideas.

Thanks,
- Manish M

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
C

Chris Jones

I am creating requirement documents and would like to use a free
macro/script/etc. my work is too cheap to buy Rational Req or Doors or some
real tool

right now just having an autoincrement unique ID like captions work for
tables and figures would be great. unfortunately captions will renumber if
order is changed or additional captions (requirements are added/deleted)

I tried creating bookmarks called SRS_0001, then every time i added a
bookmark i just had to manually change to the next number. wasnt sure how i
get a index with this and still ws too manual, I wanted and autoincrement
number like the way captions worked

I also tried the Autonew macro
(http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm) and it works but adding
the bookmark and then running the macro is sorta cumbersome any ideas or
tweaks you could suggest.

your post suggested that it would take quite a bit of VBA code for Mukherjee
but I am assuming that was to address the pending stuff. i i just wanted
hard requirements can you recomend a process or procedure?

John McGhie [MVP - Word and Word Macinto said:
Hi Manish:

This sounds to me like you're creating software requirements specifications
:)

Yes, you can indeed to it with document variables and (quite a lot...) of
supporting VBA code.

Rational Requisite Pro uses bookmarks, macros, and a database to achieve the
result.

Since you are in a software development team, grab one of the coders and ask
them to run it up for you. Or buy a copy of ReqPro. Or ping me or one of
the others by email and we can negotiate a fee for this. I am afraid your
precise requirement represents more coding than most of us would be willing
to do without charge.

I would probably approach the task by using one of the fields that is not
used for anything else in the document. I would probably choose the 'TC'
field, since Word automatically expects lots of them, and they can contain
text, and the text does not have to be unique.

I would create a macro that added a paragraph, set the paragraph to your
chosen Style, and added a TC field at the front with the text "req-pend"

I would create another macro that intercepted the Document.OnSave event. It
would then enumerate the Fields collection, and evaluate the text string
within each. The macro would need to parse right after the string 'req-'
and retrieve the integer it found there, loading all of the integers into an
array.

It would then need to sort the array (you need a WordBasic command for that,
VBA can't sort arrays). Look for the highest integer and set it into an
integer variable.

Then run through the TC fields collection again, take the first "pend" field
you find, change "pend" to the next highest integer, and so on, until you
reach the end of the collection.

Then allow the Save to complete.

Such a design is slow but quite robust. Of course, you would not need to
evaluate the entire collection if you stored the highest number in use in a
Document Variable. But if you did that and someone forgot to run the macro,
your macros would be unable to recover.

You might gain speed by using a hybrid design: using Bookmark fields for the
confirmed requirements and some other field for the Pending requirements.
Bookmark fields must have unique names, but they're stable and the
collection enumerates rapidly.

Hope this helps


All,
I want to create a MS-WORD dcoument of the following format:

req-1 This is statement 1
req-2 This is statement 2
req-3 This is statement 3

The key is:
1. These numbers must be assigned automatically (by use of a macro or
otherwise). When a statement is inserted and a predefined paragraph style is
applied for it, the line should transform into:

req-pend this is statement 4
Once the user saves the document, the document should automatically change
this line to:

req-4 this is statement 4.

2. If I remove req-2, the numbering for req-3 should NOT change
3. If I insert another line after req-3, after I had deleted req-2, it
should be inserted as req-4

The basic idea is that once a statement is added in and a number assigned to
it (e.g. req-2), this number should never be reused for the life of this
document.

I understand that I could use document variables to achieve this. Can anyone
point me to an example or give me some ideas.

Thanks,
- Manish M

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 
J

John McGhie [MVP - Word and Word Macintosh]

Hi Chris:

It's still more coding than I'm prepared to do for free :)

Any kind of auto number in Word will change if you move it. So you are down
to hand-typing the number.

You can make a macro to do that for you, but where's it going to get the
"next" number from? A typical software project has multiple requirements
documents and multiple authors. So the number has to be external to the
document, the machine, and the registry.

That assumes that it's lodged in a network resource of some kind. And that
the macro can get exclusive access to the file, and retry gracefully if it
happens to hit it at the instant another user does.

Then we have to make some wild assumption that the "next" number will be the
next higher number. That would be safe if you imposed a policy that says a
number once used can not be re-used for the life of the project. If you
re-use the numbers from deleted requirements, then you have to store a
matrix (e.g. An Excel spreadsheet) on the network, and inspect it to take
the next unpopulated cell.

The "requirement" (!) is simple enough, but coding it so that it is "robust"
is non-trivial.

Let me suggest a work-around for you:

1) Use Heading 3 style for the title of each requirement.
2) Display the document in Document Map view.

You can then collapse the outline so you see only the Heading 3 paragraphs,
so you can see at a glance which numbers have been used in the document.

Type the next one in by hand at the front of the Requirement title. It's
ordinary text. Unlike a number field, it won't change if you move it or cut
it. Unlike a bookmark, it won't get mangled if you edit carelessly
(software developers are notorious for their inability to edit cleanly in
Word!!)

3) Adopt a convention that each requirement document has a two-digit prefix
that is prepended to its numbers.

That gives you up to 100 requirements documents in a project, all with
globally-unique numbers.

And it doesn't cost anything :)

Cheers

On 15/3/06 3:11 PM, in article
(e-mail address removed), "Chris Jones" <Chris
I am creating requirement documents and would like to use a free
macro/script/etc. my work is too cheap to buy Rational Req or Doors or some
real tool

right now just having an autoincrement unique ID like captions work for
tables and figures would be great. unfortunately captions will renumber if
order is changed or additional captions (requirements are added/deleted)

I tried creating bookmarks called SRS_0001, then every time i added a
bookmark i just had to manually change to the next number. wasnt sure how i
get a index with this and still ws too manual, I wanted and autoincrement
number like the way captions worked

I also tried the Autonew macro
(http://word.mvps.org/FAQs/MacrosVBA/NumberDocs.htm) and it works but adding
the bookmark and then running the macro is sorta cumbersome any ideas or
tweaks you could suggest.

your post suggested that it would take quite a bit of VBA code for Mukherjee
but I am assuming that was to address the pending stuff. i i just wanted
hard requirements can you recomend a process or procedure?

John McGhie [MVP - Word and Word Macinto said:
Hi Manish:

This sounds to me like you're creating software requirements specifications
:)

Yes, you can indeed to it with document variables and (quite a lot...) of
supporting VBA code.

Rational Requisite Pro uses bookmarks, macros, and a database to achieve the
result.

Since you are in a software development team, grab one of the coders and ask
them to run it up for you. Or buy a copy of ReqPro. Or ping me or one of
the others by email and we can negotiate a fee for this. I am afraid your
precise requirement represents more coding than most of us would be willing
to do without charge.

I would probably approach the task by using one of the fields that is not
used for anything else in the document. I would probably choose the 'TC'
field, since Word automatically expects lots of them, and they can contain
text, and the text does not have to be unique.

I would create a macro that added a paragraph, set the paragraph to your
chosen Style, and added a TC field at the front with the text "req-pend"

I would create another macro that intercepted the Document.OnSave event. It
would then enumerate the Fields collection, and evaluate the text string
within each. The macro would need to parse right after the string 'req-'
and retrieve the integer it found there, loading all of the integers into an
array.

It would then need to sort the array (you need a WordBasic command for that,
VBA can't sort arrays). Look for the highest integer and set it into an
integer variable.

Then run through the TC fields collection again, take the first "pend" field
you find, change "pend" to the next highest integer, and so on, until you
reach the end of the collection.

Then allow the Save to complete.

Such a design is slow but quite robust. Of course, you would not need to
evaluate the entire collection if you stored the highest number in use in a
Document Variable. But if you did that and someone forgot to run the macro,
your macros would be unable to recover.

You might gain speed by using a hybrid design: using Bookmark fields for the
confirmed requirements and some other field for the Pending requirements.
Bookmark fields must have unique names, but they're stable and the
collection enumerates rapidly.

Hope this helps


All,
I want to create a MS-WORD dcoument of the following format:

req-1 This is statement 1
req-2 This is statement 2
req-3 This is statement 3

The key is:
1. These numbers must be assigned automatically (by use of a macro or
otherwise). When a statement is inserted and a predefined paragraph style is
applied for it, the line should transform into:

req-pend this is statement 4
Once the user saves the document, the document should automatically change
this line to:

req-4 this is statement 4.

2. If I remove req-2, the numbering for req-3 should NOT change
3. If I insert another line after req-3, after I had deleted req-2, it
should be inserted as req-4

The basic idea is that once a statement is added in and a number assigned to
it (e.g. req-2), this number should never be reused for the life of this
document.

I understand that I could use document variables to achieve this. Can anyone
point me to an example or give me some ideas.

Thanks,
- Manish M

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Microsoft MVP, Word and Word for Macintosh. Consultant Technical Writer
Sydney, Australia +61 (0) 4 1209 1410
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top