Combining IF field and SYMBOL field fails

J

John in Saratoga

I need to insert text into a Word document conditionally, so I'm using the IF
field. For the text itself I need to use the SYMBOL field (for reasons I
needn't describe). But I can't get IF and SYMBOL to work together.

The field code
{ NUMPAGES } returns number of pages and
{ SYMBOL 65 } returns the letter A, as they should. (Those of course are
real field braces.)

But, while
{ IF 2 > 1 { NUMPAGES } }
also returns the number of pages
{ IF 2 > 1 { SYMBOL 65 } }
returns nothing at all.

Huh?

Word 2003 on XP. Tried two different machines. Same result.

{ IF 2 > 1 { SYMBOL 65 } "false"} returns nothing also, so the conditional
is evaluating TRUE. It's as if SYMBOL just fails when inside an IF field.
 
P

Peter Jamieson

Unfortunately, I think it has always been this way (from at least Word 97).
Nor can you do

{ SET X { SYMBOL 65 } }
{ IF 1 = 1 "{ SYMBOL 65 }" "" }

(even { REF X } does not do what you might hope, and the common workaround
of using { QUOTE }doesn't work either.

So...if it /has/ to be SYMBOL, I don't think there's a simple way forward.
You can put an IF inside the SYMBOL, so you can do, e.g. an individual
character or a space:

{ SYMBOL "{ IF 1 = 1 "65" "32" }" }

but that's about the closest you can get. What effect do you need to
achieve?

Peter Jamieson
 
J

John in Saratoga

Thanks Peter. Here is what I'm trying to do:

The field { PAGE } returns its results using the ten characters 0-9 (ASCII
hex 30-39). My font (LTC Caslon) has an alternate set of glyphs for the ten
digits (the old style where 3, 4 and 5 dip below the baseline), and I want to
render page numbers with these alternate characters. They are UNICODE
characters F730-F738.

The field { SYMBOL } with a little arithmetic on the result of { PAGE } does
the trick but I get a leading 0 when the page # is less than 10. So I want to
drop my little formula inside an IF { PAGE } > 10.

I have a work-around in which I put the IF inside the SYMBOL. The font
happens to have a zero-width character and I use that where the leading zero
would be. The work-around isn't ideal since that zero-width character isn't
well-behaved across fonts, but it works OK.

Do you know another way to get to transpose the characters that result from
{ PAGE } to another place in the character table?

I wondered if I could write a custom field in VBA, but I haven't seen a way
to do that.

Thanks again,
John
 
T

Tony Jollans

Not sure exactly how you're accomplishing what you have so far, but a couple
of options ...

(a) Instead of doing ...

{ IF 2 > 1 { SYMBOL 65 } }

What about

{SYMBOL { IF 2 > 1 65 } }

(b) Instead of using a symbol field can you not use the actual character in
your IF field?

( IF 2 > 1 ? )

where ? is U+F730, etc.
 
P

Peter Jamieson

Tony's second approach should do the trick as long as you are prepared to
write all the necessary nested IF statements to do it (and I think that
requires that you know the maximum number of digits in your page number).
(Anyone else responding to this message needs to remember that if you can't
use SYMBOL, you need an IF, or alternative, that has a different result for
each digit).
I wondered if I could write a custom field in VBA, but I haven't seen a
way
to do that.

If only. There is no such facility. There are some things that come close,
but they tend to be undermined in one way or another, e.g., they don't work
as you might hope in headers/footers (e.g. INCLUDETEXT fields), or they
don't update when you expect, or users end up having to answer increasingly
spooky security questions (e.g. DATABSE fields or anything else that Word
thinks needs to "execute" something, or they add unwanted paragraph markers
(e.g. recent DATABASE field implementations and external text converters)

An alternative approach which might work if
a. you have sufficient control over the documents concerned
b. the page number range is limited
c. you are using a sufficiently recent version of Word (i.e. one where
docvariable fields in headers and footers do not crash the product)

could be
d. to use VBA to create a Word.Variable in the document for each page
number you want to use

e.g. create docvariable p123 with value "xyz", where x, y, and z are the
unicode character codes for the digits 1,2,3 in your font

e. use a nested field code such as

{ DOCVARIABLE "p{ PAGE }" \*charformat }

where the "D" is formatted in the font you want to use.

Peter Jamieson
 
J

John in Saratoga

Thanks for all the excellent ideas.

Here is what I've done. The number of pages is less than 1000. I handle each
of the three digits separately and concatenate the result.

{ SYMBOL { IF { PAGE } > 99 { = 63280 + mod(int({ PAGE }/100),10) } 160 } }
{ SYMBOL { IF { PAGE } > 9 { = 63280 + mod(int({ PAGE }/10 ),10) } 160 } }
{ SYMBOL { = 63280 + mod({ PAGE },10) } }

In the font, the characters I want are in the range 63280 to 63289 and
Unicode character 160 happens to be a zero-width character.

John
 

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