Ask Your Question
0

How can I set text based on two variables? [closed]

asked 2013-06-20 04:24:43 +0100

chasbelov gravatar image

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?

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2015-11-02 19:03:40.691841

2 Answers

Sort by » oldest newest most voted
1

answered 2013-06-21 00:54:31 +0100

chasbelov gravatar image

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.

edit flag offensive delete link more

Comments

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.

oweng gravatar imageoweng ( 2013-06-21 01:38:05 +0100 )edit
0

answered 2013-06-20 07:01:21 +0100

oweng gravatar image

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.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-06-20 04:24:43 +0100

Seen: 340 times

Last updated: Jun 21 '13