cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

We are working to address an issue with subscription email notifications. In the meantime, be sure to check your favorite boards for new topics.

How to define multiple variables from the results of a single IF statement?

kwadley
1-Newbie

How to define multiple variables from the results of a single IF statement?

A simplified example probably illustrates my question best:

question.PNG

I would like to set multiple variables based on the value of A in my example above.

Thanks,

Kevin

1 ACCEPTED SOLUTION

Accepted Solutions
LucMeekes
23-Emerald III
(To:kwadley)

You're using the 'equals' operator "=" where you should use the assignment operator for programs "<-".

So do like this:

You use:

to test if A equals the string "Value1". The result is either True (nonzero) or false (zero).

You use:

to assign a value of 3 to the variable x, outside of programming.

Inside of a program, the assignment should look like:

Success!
Luc

View solution in original post

5 REPLIES 5
LucMeekes
23-Emerald III
(To:kwadley)

You're using the 'equals' operator "=" where you should use the assignment operator for programs "<-".

So do like this:

You use:

to test if A equals the string "Value1". The result is either True (nonzero) or false (zero).

You use:

to assign a value of 3 to the variable x, outside of programming.

Inside of a program, the assignment should look like:

Success!
Luc

StuartBruff
23-Emerald II
(To:kwadley)

Kevin Wadley wrote:

A simplified example probably illustrates my question best:

question.PNG

I would like to set multiple variables based on the value of A in my example above.

Luc's answer is the correct one.  Here's another way of assigning values en masse that I sometimes use to make a program more visually compact.  Given that Mathcad can do calculations inside an array, you can also use a variant of this method to attach comments to an expression (to ensure they remain aligned).

Stuart

Luc & Stuart-

Thank you for the reply, but I'm still not exactly there.

I want to use my results of my IF statement outside of the program, so I need to define multiple variables outside the program as well.

For example, I need to define variables X, Y, & Z from the results of my program:

Capture.PNG

where X = x+y+z

          Y = 2x

          Z = 4y

Thanks again,

Kevin

Maybe that way:

You may also consider turning the routine into a function with A as argument.

WE

Thanks all!

I thought you might like to see my final program:

Complete.PNG

Comments are appreciated if you see something I could do better.

Kevin

Top Tags