Field Codes question (Word 2003)

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15631
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Field Codes question (Word 2003)

Post by ChrisGreaves »

The attached document is a stripped-down version of a table used as a catalogue of documents.

When I think of a new essay I insert a row at the top, type in the title, and paste what is now the second row sequence field "Coming" into the first row cell.
If I want to know how many items are in-the-pipeline I select all and update the fields (Ctrl-A, F9)

When I compile an essay, I drop today's date into the next item in the pipeline (the first "Coming" row above the previous dated item), and away w go.
If I select all and update the fields (Ctrl-A, F9) I will see, of course, one less count for items in the pipeline.

How might I replace my "coming" sequence fields with a date-field, so that the date immediately above the most recently published essay (in my example "One Page Fits All") would read the next higher date, and so on up the table?

That is, I'd like a date field whose result was Tuesday, June 28, 2011 for "Sales – Moving Forwards", was Wednesday, June 29, 2011 for "Make a Copy!", and was Thursday, June 30, 2011 for "Linkedin – and the Drudgery of Updating Same", and so on.
So that if someone asked me "When is "Life-time Technical Assistance" scheduled to be published?" I could read off the date field and give them a real date, instead of saying "Oh, about 8 days from now". (My real index has 33 items in the pipeline, so mentally calculating dates is not a trivial exercise).

P.S. Nice-to-have would be the ability to skip one day a week, as in "I don't publish on Sundays", but I can live without that.

P.S. There is another Free Lunch at The Montreal Deli in it for the best entry submitted.
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
HansV
Administrator
Posts: 78500
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Field Codes question (Word 2003)

Post by HansV »

See macropod's tutorial DateCalc.zip, available from the Third party downloads section in Downloadable files on Graham Mayor's website. Make sure that you read the introductory notes carefully.
Best wishes,
Hans

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15631
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Field Codes question (Word 2003)

Post by ChrisGreaves »

HansV wrote:See macropod's tutorial DateCalc.zip,
Hi Hans.
:whisper: Don't tell anyone, but I already had a look through there.


I couldn't see a serial date calc that worked backwards, so to speak.
Did you have a specific instance in mind?

(later) On reflection, I think my specs, such as they were, left something out.
I really want the date field in any row to calculate one less than the date field in the row below, so there is more than just a date calculation here; it's a date calculation based on the next higher cell, and it ought to be relative, so that I can, as an example, copy-and-paste a row in place mid-table and have it maintain a correct incremental sequence, as can be done, of course, with the {SEQ}.

The {SEQ} field works from the head of the document to the the foot of the document, values increasing in a forwards sense.
I'm interested in a date adjustment with a {SEQ} that works backwards, growing larger in the foot-to-head direction.
There's nothing heavier than an empty water bottle

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Field Codes question (Word 2003)

Post by macropod »

Hi Chris,

As Hans said, see my Microsoft Word Date Calculation Tutorial. in particular, see the topic 'Calculate a Date Sequence'. You could employ the 2nd & 3rd field sets there, modified as follows:

1. Delete the '+Delay' from line 7 of the 2nd field from the tutorial, so that you end up with:
{QUOTE
{SET Delay 1}
{SET a{=INT((14-{DATE \@ M})/12)}}
{SET b{={DATE \@ yyyy}+4800-a}}
{SET c{={DATE \@ M}+12*a-3}}
{SET d{DATE \@ d}}
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}}
{SET e{=INT((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)/1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
"{dd}-{mm}-{yy}" \@ "dddd, d MMMM yyyy"}
This simply gives one less field to work with and makes the handling of your 'Sundays off' easier to process.

2. For an ascending date sequence, modify line 2 of the 3rd field from the tutorial so that you end up with:
{QUOTE
{SET jd{=jd+(MOD(jd,7)>4)*(6-MOD(jd,7))+Delay}}
{SET e{=INT((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)/1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
"{dd}-{mm}-{yy}" \@ "dddd, d MMMM yyyy"}
This mod provides your 'Sundays off'.

2. For a descending date sequence, modify line 2 of the 3rd field from the tutorial so that you end up with:
{QUOTE
{SET jd{=jd-(MOD(jd,7)=0)-Delay}}
{SET e{=INT((4*(jd+32044)+3)/146097)}}
{SET f{=jd+32044-INT(146097*e/4)}}
{SET g{=INT((4*f+3)/1461)}}
{SET h{=f-INT(1461*g/4)}}
{SET i{=INT((5*h+2)/153)}}
{SET dd{=h-INT((153*i+2)/5)+1}}
{SET mm{=i+3-12*INT(i/10)}}
{SET yy{=100*e+g-4800+INT(i/10)}}
"{dd}-{mm}-{yy}" \@ "dddd, d MMMM yyyy"}
This mod provides your 'Sundays off'.
Last edited by macropod on 30 Jun 2011, 23:30, edited 2 times in total.
Paul Edstein
[Fmr MS MVP - Word]

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15631
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Field Codes question (Word 2003)

Post by ChrisGreaves »

HansV wrote:See macropod's tutorial DateCalc.zip,
Ahem!
I have now d/l a later version than the one I had been using.
Thanks Hans.
There's nothing heavier than an empty water bottle

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15631
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Field Codes question (Word 2003)

Post by ChrisGreaves »

This response is to let you know of my progress, and to thank you for your help!
macropod wrote:1. Delete the '+Delay' from line 7 of the 2nd field from the tutorial, so that you end up with:
{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045}}
This simply gives one less field to work with and makes the handling of your 'Sundays off' easier to process.
2. For an ascending date sequence, modify line 2 of the 3rd field from the tutorial so that you end up with:
{SET jd{=jd+(MOD(jd,7)>4)*(6-MOD(jd,7))+Delay}}
This mod provides your 'Sundays off'.
Hi Paul, much as I admire you (and that's a lot) I think your brain must look very much like the Great Barrier Reef, and to my puny mind, is - I was going to say "unfathomable", but then realized that corals grow in shallow water, so "unfathomable" would hardly be the right word. That's how easily I get confused!

I spent a few sessions with the mods, and I am partway there. (attached)
I have managed to see the Julian Date rising in sequence, and skipping Sundays, so I have managed to follow your excellent instructions to that extent.

I finally remembered having to make a change (years ago) to swap the dd & mm values in the fields; otherwise I get dates in November. My clue is that the dates advance a month at a time, rather than a day at a time, so my day/month are swapped.
I imagine that that is because of the date format I use. I further imagine that you have warned me about that in the epistle of Paul!

Now that the dd/mm is worked out I am going to persevere and get these fields operating in my table.

This response is to let you know of my progress, and to thank you for your help!
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15631
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Field Codes question (Word 2003)

Post by ChrisGreaves »

macropod wrote:This mod provides your 'Sundays off'.
Hi Paul.
I continue to dabble, but have stumbled across something that I find rather weird (and hence delightful).

This morning (attached) I decided to start loading up the table cells with dates, and thought that I'd screwed up the formatting, but all I'd done was paste one date field from the experimental list (at the foot of the document) into several cells in column 1 of my table.

My table now starts off at July 21st, which is one day after the last date at the foot of the document!

It seems that the values for "jd" are carried in the order in which they (the fields) are created in the document, and since I pasted fields into the table, at the head of the document, at a time later than those in the body, at the foot of the document, the "jd" values at the foot take effect before the pasted values at the top.

Can this be right?
You do not have the required permissions to view the files attached to this post.
There's nothing heavier than an empty water bottle

User avatar
macropod
4StarLounger
Posts: 508
Joined: 17 Dec 2010, 03:14

Re: Field Codes question (Word 2003)

Post by macropod »

Hi Chris,

The jd fields update according to their position in the document, not according to the order in which they're inserted. If, of course, you only update some of the collection, the updates can occur out of order and strange effects can ensue.
Paul Edstein
[Fmr MS MVP - Word]