How can I set text based on two variables?

I would like to set a variable to display text in Writer 4 on the basis of two other variables, e.g.:

  1. If A is true and B is true, set C to display “one”.
  2. If A is true and B is false, set C to display “two”.
  3. If A is false and B is true, set C to display “three”.
  4. If A is false and B is false, set C to display “four”.

I want to set C as a variable as I will be displaying the resulting text multiple times throughout the document.

I have not been able to figure out a way to accomplish this. I tried using hidden sections, but hidden sections only don’t print; they still affect the value of variables even if hidden.

I also tried using Insert > Field > Other > Insert Formula, but couldn’t come up with a formula that Writer recognized as valid. Specifically, I tried using a Calc compound IF:

IF(A EQ “1”,IF(B EQ “1”,“one”,“two”),IF(B EQ “1”,“three”,“four”))

but got an error message.

On the other hand, there doesn’t seem to be a way to set a variable based on a compound condition, at least not so I can get four different results.

Is there a reasonable way to accomplish this without manually having to change the value of C every time I change the value of A or B, which also control text throughout the document?

Thank you for the suggestion. Yes, I would be manually setting A and B.

I gave the macro a shot but was put off by the minimal documentation for working with fields in the Macro Programmers Guide. Alas, searching did not turn up any list of function calls or examples. So I went with a simpler, if a bit clunkier solution.

I ultimately solved it by inserting sections which I showed or hid based on variable B, then put conditional text into these sections based on variable A. Not quite the same as using them to set a third variable, but at least it worked.

Interestingly, using hidden sections to set the third variable does not work as a strategy, as hiding the section does not prevent the hidden section from setting the third variable.

Thanks for reporting back and detailing your solution. Andrew Pitonyak is currently assisting the documentation team in getting a Macro Guide prepared for LO. This should significantly improve the documentation in this area.

I think this type of nested logic demands the use of a macro that interrogates the value of variable A and B, which you appear to be manually setting.