Test DocVariable in IF Statement? COMPARE statement?

K

KGB

I am trying to get the following formula to produce the text "True" or
"False" with the following IF field:

{IF {DocVariable VarName} = 3553 "True" "False"}

The variable is currently set to 3556, and I have successfully inserted it
into the document with the following field:

{DocVariable VarName}

I just can't seem to successfully test the variable. It currently produces
the following text:

VarName}

If I take out the space before and after the equal sign, it generates this:

VarName}=3553

If I instead add enclose VarName in another set of brackets, I get this:

{VarName}}

If I instead use a COMPARE statement, it always returns 1, even though I
have confirmed that the variable is still set to 3556:

{COMPARE {DocVariable JWWordCountVar2} = 3553}

Any help is appreciated.
 
G

Gordon Bentley-Mix at news.microsoft.com

KGB,

I can't tell you what's going on with the IF statement, but I suspect that
the results you're seeing for the COMPARE statement are because COMPARE
returns 1 for True and 0 for False. What happens if you change the value in
the variable?
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
K

KGB

On the compare statement, I was getting 1 but should have been getting 0, as
the variable was set to 3556 and I was asking if it was = 3553. I did try
several other values with the same results.
 
G

Gordon Bentley-Mix at news.microsoft.com

Including 3553? If so, then stuffed if I know what's going on. But then
fields aren't really my strong suit; I'm more of a VBA guy. ;-P I'll have a
play and see what I can figure out. In the meantime, maybe somebody like Doug
Robbins or Jay Freedman will have an answer.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
G

Gordon Bentley-Mix at news.microsoft.com

KGB,

I tested in Word 2003 on Windows XP using the following constructions:

{ IF { DOCVARIABLE TEST } = "123" "True" "False" }
and
{ COMPARE {DOCVARIABLE TEST } = "123" }

When the value of the document variable "TEST" is "123" the first
construction returns "True" and the second returns "1". When the value of
"TEST" is "456" (or anything other than 123), the first returns "False" and
the second returns "0". This is as I would expect it to be. Therefore, I am
unable to replicate the issue. Have you tried recreating the fields from
scratch? Perhaps they've become corrupted or you've accidentally inserted a
curly brace ("{", "}") manually...?
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
K

KGB

It's always the simple stuff ("Perhaps ... you've accidentally inserted a
curly brace ("{", "}") manually...?")

Thanks, this works great now.
 
G

Gordon Bentley-Mix at news.microsoft.com

As my daughter once said at age 4 whilst watching a cartoon wherein a horse
and rider were struck by lightning, revealing their bones: "Horses hate that
when that happens!" <g>

Glad I could help.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 
B

Barry Schwarz

I am trying to get the following formula to produce the text "True" or
"False" with the following IF field:

{IF {DocVariable VarName} = 3553 "True" "False"}

The variable is currently set to 3556, and I have successfully inserted it
into the document with the following field:

{DocVariable VarName}

I just can't seem to successfully test the variable. It currently produces
the following text:

VarName}

If I take out the space before and after the equal sign, it generates this:

VarName}=3553

If it actually prints the brace, it means you entered the } as text.
You need to enter it using Ctrl-F9.
 
N

nicola deogun

spacing and punctuation are really important in the structuring of an 'if' statement.

{ IF { DOCVARIABLE VarName } = "Number" "True" "False" )

The " " around each part of the statement must be consistent, ie., you either have "" around each element or you have none.

Hope this helps.
 

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