Results 1 to 10 of 10
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    If statements in field codes (W97, WinNT4)

    Hi folks

    I have been trying to get a running balance in a table by putting the following if statement in a cell (obviously using Ctrl-F9 to get the curly brackets):

    { if b5<>"" { =a10+b5 } "" }

    which by my understanding should mean "if there is anything in cell b5 then add the contents of cells a10 and b5 else leave empty". But it doesn't.

    Where am I going wrong?! I've tried every combination I can think of, putting {} around each element, turning it around, putting a hyphen in the b5 cell and saying ' if b5 = "-" ...' but I cannot get it to actually note both halves of the true and false sections. Sometimes it will add the cell contents but won't blank it if there's nothing there; other times it blanks it but won't add ... <img src=/S/crazy.gif border=0 alt=crazy width=15 height=15> I'm going crazy! <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

    I expect it's something stupid, but I can't spot it! Please help!
    Beryl M


  2. #2
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Sun Prairie, Wisconsin, Wisconsin, USA
    Posts
    2,048
    Thanks
    124
    Thanked 119 Times in 116 Posts

    Re: If statements in field codes (W97, WinNT4)

    This is why I use Excel!

    You might try putting quotation marks around your calc field and see if that helps. My rule with IF (and REF) fields is: when in doubt, put quotation marks around everything! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Charles Kyle Kenyon
    Madison, Wisconsin

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: If statements in field codes (W97, WinNT4)

    The only way I could get the first table cell reference to be recognized was this way:

    { IF { =B2 } = 0 "WORKS" "FAILS" }

    Using the equation field evaluated a blank cell to 0. If this doesn't work for your application, then it's back to the drawing board...

    (A while later...)

    Try this:

    { IF { =COUNT(B2) } = 0 "WORKS" "FAILS" }

    The True result is returned for a blank or any nonnumeric value. Otherwise, False is returned. Okay, I only tested about 4 values, but it seems to work. I am using Word 2000.

  4. #4
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: If statements in field codes (W97, WinNT4)

    I couldn't get it to work unfortunately. So, I tried the other possibility - setting it up in XL. And now I've got a new problem.

    You see, this document contains a list of chapter numbers, with the number of words in the chapter and a running total of words in the book so far (yes, I'm one of those perenially hopeful would-be authors!), and the template I've set up automatically trawls the chapter docs and puts in the number of words in each; the if statements were supposed to stop it putting the same figure for the running total against the so-far unwritten chapters' number of words - 0, of course.

    So - I've set the doc up in XL, but now I don't know how to get XL to do the same thing! I attach a zipped copy of the Word version - I'm sure it could be done in a neater way, but I'm not up to some of the more esoteric programming yet! - and would be grateful if someone could point me in the right direction!

    Many thanks in advance.
    Attached Files Attached Files
    Beryl M


  5. #5
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If statements in field codes (W97, WinNT4)

    Hi Beryl:

    You left out parentheses to group a10 & b5 AND you left out putting them in quotes (for your true result). The field should look like this:

    { If b5 <> 0 "{ = (a10+b5) }" "" }, OR
    { If b5 <> "" "{ = (a10+b5) }" "" }

    Cheers,

  6. #6
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If statements in field codes (W97, WinNT4)

    Hi Charles:
    >>My rule with IF (and REF) fields is: when in doubt, put quotation marks around everything! <<

    I used to do that all the time too. In fact, I used to start the field by putting in braces, then typing IF, & then 3 sets of quotes, filling them in later. Then I found that if I tried the following field in a header:

    {IF "{Page} = {Numpages}" "Approved by:" ""}

    it didn't work correctly. I had to remove the quotes before page & after numpages for it to work correctly.

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: If statements in field codes (W97, WinNT4)

    Thanks for trying, Phil, but still no go! It adds up the columns quite happily but will not accept the false statement - I even tried putting something inbetween the quotes to put in if false but it won't have it.

    <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>
    Beryl M


  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Los Angeles Area, California, USA
    Posts
    7,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: If statements in field codes (W97, WinNT4)

    Hi Beryl:
    Yep, sorry. I rechecked it & the false field didn't come through. I will investigate a little further. Even tried it with bookmarks & that didn't work either. <img src=/S/brickwall.gif border=0 alt=brickwall width=25 height=15>

  9. #9
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: If statements in field codes (W97, WinNT4)

    Change the test as described in my message. See attached sample.
    Attached Files Attached Files

  10. #10
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: If statements in field codes (W97, WinNT4)

    Jefferson, you're a marvel! I did try your earlier suggestion but it didn't work then - and I can't see what's different in your latest one, but it does work now!

    I don't know what we'd do without you around here!

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •