Help with IF statements
-
I have used simple 'IF' statements before but now I have a problem that I'm not sure can be resolved with a series of IF statements and would appreciate any guidance.
I have four attributes (Question1, Question2, Question3 and Question4) all of which can have an answer 'Yes' or No'.
I have a fifth attribute (Colour) which has a value (Red).A sixth attribute (Answer) has to be automatically completed depending on the values of the four questions. The value of this attribute has to be filled with four values seperated by a - depending on the answers to the four questions.
Example
- if 'Question1' is 'Yes' and the other three are 'No' then 'Answer' is 'Red-0-0-0'
if 'Question1' and 'Question2' are 'Yes' and the others 'NO' then 'Answer' is 'Red-Red-0-0' etc.
If this is possible, any assistance would be appreciated.
- if 'Question1' is 'Yes' and the other three are 'No' then 'Answer' is 'Red-0-0-0'
-
You say the "answer". But how is the answer being used? Just output into a non-editable field? Or used internally inside the component? I think how the answer will be used is important. Any insights to that?
Chris
-
Also, does the 5th value chagnge? Are there options given to the user?
Amd is there a reason that the 6th element has to be a single element? Could it be split up into 4 elements?
-
Ok, here is the solution the way I think you were asking.
There are 4 yes or No questions. One color option, and one final output box. The yes and no boxes can be changed by the user, and the user can select any of the pre-defined colors. Then the output box shows 0-blue-0-blue etc based on their yes/no and color selections.
The q1-q4 lines are the option boxes. Z_Q1_HODER entries evaluate display either the chosen color or a 0, depending on the values entered for q1.
Then the answer entry concatenates the z_qx_holder values into a single line and displays that for the user to see. The code is not tricky, but you might want to copy it out of the DC editing box into a text editor to be able to read it better. Hope it helps and is what you wre looking for,
Chris
-
Thanks Chris.
Sorry I didn't get back to you on your first two reponses, it was the middle of the night here when I posted and I've only just got back to my PC.
Looking at the sample I think it is exactly what I need except for a couple of things which I can easily change.
The only user input is answering the four questions - the colour is fixed, taken from another input box elsewhere.
The final answer is also invisible to the user as this concatented field is used as a data filed in a report exported to file for use in another programme.
I thought about doing the script as four if statements, but was unfamiliar with the 'Concatenate' formula and how to combine four attributes into one with the - separator included, but your example was extemely useful is showing me how it is used. Doing it this way also makes life a bit easier in making the component as the question input can be put into the main component of a model (with all the other input) and then the answer copied down to all sub components in the model - saving the need to put it into every part.
Later today I will transfer your sample to my test model and see how it goes - but I'm sure it will give me what I need.
Thanks again
-
Yeah, it was the middle of the night here too, about 2:00am when I finished I think. I was having one of those sleepless nights. So I was not worried about waiting for responses. I was mostly just thinking out loud I think.
Anyhow, glad it helped. It was a fun exercise in DC's.
Chris
-
@unknownuser said:
It was a fun exercise in DC's.
Yes they are fun - to start with.
I have a whole stack of them to do to produce a complete kitchen cabinet catalogue
I am trying to construct a complete drawing, customer quote and ordering/manufacturing system, and DC's are a godsend for this, although there are issues they don't address that I will have to deal with, and with no coding experience/skills that should be interesting
-
Good luck with that. I'm about to start digging into DC's through ruby, so I'll probably be asking questions about some of this in the near future.
Advertisement