"AND" (compound conditions)

M

Monika Krug

(version: Word 2003)

I hope someone can help me with this problem, it is
driving me crazy:

I have these fields in my document:
(The /* comments */ are added for clarity here.)

{ IF { MERGEFIELD "associations" } = "070" { SET v070
true } { SET v070 false } } { NEXTIF v070 } /* as the
first record has associations=070, this results in v070
being set to true and Word going to the next data record */

v070: { v070 } /* shows v070 for debugging - true as
expected */

less: { IF { MERGEFIELD "Index_070" } < {
MERGEFIELD "Total_070" } true false} /* this should be
true, because 1 is less than 3 */

{ SET more { = AND (v070; { IF { MERGEFIELD "Index_070" }
< { MERGEFIELD "Total_070" } true false}) } } /* here is
the trouble */

more: { more } /* this should be 1, as true and true
results in true - but it is not working */

{ IF v070 "{ MERGEFIELD Index_070 }/{ MERGEFIELD
Total_070 }"} /* shows 1/3 as expected */

The relevant columns of the first four rows of data are:
associations; Total_070; Index_070;
070; ; ;
; 3; 1;
; 3; 2;
; 3; 3;
(I.e. for the first record associations=070 and the total
and index are empty, for the other records associations is
empty, total is always 3 and index is counted from 1 to 3.
The part I show above only uses the first two records.)

The shown result is:

v070: true
less: true
more: 0
1/3

Why is the result of the AND field 0, even though both
parts are true?! I don't get it. What is wrong? Am I using
AND incorrectly?

I have tested { = AND (true; 1) } and different
combinations of true, false, 0, and 1 in the brackets
after AND - the result was always as expected, e.g. = AND
(true; 1) yields 1.

Any ideas?


Different, not so important question: I think { = AND
(v070; { MERGEFIELD "Index_070" } < {
MERGEFIELD "Total_070" } ) } should be working, too,
instead of { = AND (v070; { IF { MERGEFIELD "Index_070" }
< { MERGEFIELD "Total_070" } true false}) } . Any ideas
why it does not work at all? I get a "!Syntax Error, <".


I have another weird problem with the same mail merge
document:

1. When I open it and preview for the first time (with the
first data record, or actually with the first two as I use
nextif), the result is true, true, 0, 1/3 as shown above,
so as expected except for the weird 0.

2. When I highlight all and press F9, suddenly true,
false, 0, / are displayed. How is that possible?!

3. When I click to preview the next record and back to #1,
it now shows true, true, 0, 1/3 again. (At least I have
found this workaround finally, so I don't have to close
and reopen my document all the time.)

I first thought, maybe Word now (after the second step,
i.e. after pressing F9) is at the second data record and
evaluating that one - but in that case, v070 should be
false (which remains true) and the "less" statement should
still be true, as 2<3, and not without any reason become
false.

Help particularly with the first problem would be greatly
appreciated.

Regards,
Monika.
 
M

Monika Krug

It is becoming even weirder. I have changed the fields a
little and copied it five times:

{ IF { MERGEFIELD "associations" } = "070" { SET v070
true } { SET v070 false } } { NEXTIF v070 }
v070: { v070 }
1. { SET less { IF { MERGEFIELD "Index_070" } < {
MERGEFIELD "Total_070" } true false} }{ SET more { = AND
(v070; less) } } more: { more }
{ IF more "{ MERGEFIELD Index_070 }/{ MERGEFIELD
Total_070 }"}
{ NEXTIF more }
2. { SET less { IF { MERGEFIELD "Index_070" } < {
MERGEFIELD "Total_070" } true false} }{ SET more { = AND
(v070; less) } } more: { more }
{ IF more "{ MERGEFIELD Index_070 }/{ MERGEFIELD
Total_070 }"}
{ NEXTIF more }
3. { SET less { IF { MERGEFIELD "Index_070" } < {
MERGEFIELD "Total_070" } true false} }{ SET more { = AND
(v070; less) } } more: { more }
{ IF more "{ MERGEFIELD Index_070 }/{ MERGEFIELD
Total_070 }"}
{ NEXTIF more }
4. { SET less { IF { MERGEFIELD "Index_070" } < {
MERGEFIELD "Total_070" } true false} }{ SET more { = AND
(v070; less) } } more: { more }
{ IF more "{ MERGEFIELD Index_070 }/{ MERGEFIELD
Total_070 }"}
{ NEXTIF more }
5. { SET less { IF { MERGEFIELD "Index_070" } < {
MERGEFIELD "Total_070" } true false} }{ SET more { = AND
(v070; less) } } more: { more }
{ IF more "{ MERGEFIELD Index_070 }/{ MERGEFIELD
Total_070 }"}
{ NEXTIF more }

The result shown is:


v070: true
1. more: 0
1/3

2. more: 0
2/3

3. more: 0
3/3

4. more: 0
/

5. more: 0
/

So, even though "more" evaluates to 0, it is treated as
true in the {if more ...} fields, otherwise nothing would
be printed ({ IF more "{ MERGEFIELD Index_070 }/{
MERGEFIELD Total_070 }"}).

On the other hand, it is always treated as true - the 4.
and 5. should not appear.

Does anyone understand this?

Monika.
 
M

Monika Krug

Oh oh ... I just tried something else:
{ if true "1" "2" }
{ if false "1" "2" }
both show 1.

TRUE, FALSE did not work, either (still showed 1, 1).
Neither did 1 for true, 0 for false (unknown opcode).

I guess I must be using booleans in Word's mail merge
entirely wrong :-( .

Are there no boolean literals?
Is it not possible to assign booleans to variables
(bookmarks)?

But { = AND (true, false) } worked, no matter the
capitalization and also with 1 and 0, same for OR. So
true, false must be the correct literals.

This does not make any sense to me.

Monika.
 
P

Peter Jamieson

Just looking at your first message...

The Word field language does not use the keywords or values "true" and
"false" to represent true and false. The main change you need to make is to
use 1 for true and 0 for false.

Although it is not always essential, I would do always use { REF v070 } or
{ v070 } when you want to use a bookmark value, not just v070 (no mateer
what examples you see).

It is also worth bearing in mind that Word does not necessarily perform
numeric comparisons when you use < and > operators. If you want to be sure
that Word is comparing numbers and not strings, it is better to use an { = }
field to subtract one value from the other and compare the result with 0.

Peter Jamieson
 
M

Monika Krug

Peter Jamieson said:
The Word field language does not use the keywords or values "true" and
"false" to represent true and false. The main change you need to make is to
use 1 for true and 0 for false.

Although it is not always essential, I would do always use { REF v070 } or
{ v070 } when you want to use a bookmark value, not just
v070

Thank you thank you thank you! You solved most of my mail
merge problems and saved me from certain insanity with
your post :) .

Live long and prosper,
Monika.
 
M

Monika Krug

macropod said:
For a 'tutorial' with examples of how you can do 'AND' comparisons and much
more, for both numbers and text, download the Word document at:
www.wopr.com/cgi-bin/w3t/showthreaded.pl?Number=365442
(url all one line)

Although not specifically written with MAILMERGE fields in mind, the logic,
syntax etc are the same.

Thank you! That's a very comprehensive tutorial and will
help me a lot with further mail merge problems.

A note: In your tutorial you write e.g. AND(x,y). I have
tried this and I get a syntax error. It only worked with ;
instead of ,. Maybe this was changed in a recent Word
version? The Word help also says to use a comma.

Greetings,
Monika.
 
M

macropod

Hi Monika,

At the end of the description of 'AND(x,y)', you'll see the number '1'. That
is a calculated field result using the syntax described. Select the '1' and
press Shift-F9 to reveal the field coding, which is exactly as shown in red.
In other words, it works. But, as described under 'Testing Or Returning Text
Strings With Logical Functions In Bookmarks', you need a different approach
if you're not working with numbers alone.

Cheers
 
M

Monika Krug

macropod said:
At the end of the description of 'AND(x,y)', you'll see the number '1'. That
is a calculated field result using the syntax described. Select the '1' and
press Shift-F9 to reveal the field coding, which is exactly as shown in red.
In other words, it works.

It works - until I press F9 for updating the field, then I
get a syntax error.

I have just tested it with different Word versions: On
Word 2003 AND(x;y) works, AND(x,y) does not, on Word 2002
it's the other way around.

Monika.
 
P

Peter Jamieson

A note: In your tutorial you write e.g. AND(x,y). I have
tried this and I get a syntax error. It only worked with ;
instead of ,. Maybe this was changed in a recent Word
version?

This is almost certainly because of differences in regional settings.
English USA, UK and probably elsewhere use comma as a list separator whereas
e.g. German (Germany) uses semi-colon. It looks as if the "field language"
expects that list character to separate parameter lists within fields,
whereas (for example") a language such as C would use a comma regardless of
region/locale.

Peter Jamieson
 
M

Monika Krug

Peter Jamieson said:
This is almost certainly because of differences in regional settings.
English USA, UK and probably elsewhere use comma as a list separator whereas
e.g. German (Germany) uses semi-colon.

Thank you, this must be the explanation. The regional
settings of my PC are set to German. (The PC with Word
2002 where ; worked must have been set to English.)

Monika.
 

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