NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing in formula as a string

I am attempting to use a string parameter to contain a formula that, when passed into a called sequence, will populate the value of another string and be evaluated as a formula.

E.G.

CalledStep has:

a string parameter called Name,

a number local called Val, and

a message popup step with a precondition to only run if  name equals Carl.

 

MainSequence :

is needs to pass in a formula for the parameter Name, so that inside CalledStep the name changes based on Val.

 

I have tried using "Parameters.Name = Locals.Val == 2? "+ Str("Carl") + ":" + Str("Jim") (with quotes as depicted), but it doesn't work. Watch view shows the equation in Parameters.Name but I suspect the quotes on the whole statement make it, just another string, instead of a working equation.

 

Is there a way, either in CalledStep or in the MainSequence to cause the above equation to be evaluated once inside the called sequence? Can I remove the quotes in CalledStep? Would I use an Expression (string) parameter?

 

Thank you for any help you can provide.

0 Kudos
Message 1 of 5
(4,376 Views)

I didn't expect to figure it out myself so quickly, but I didn't want to wait until I'd wasted days already to post. Anyway, I have included a sequence file that accomplishes my goal and I hope it can help someone else out.

 

I used "Parameters.Name = Locals.Val == 2? \"Carl\" : \"Jim\"" to get the equation into CalledStep and then, once within, I used the evaluate command to look at the string as an expression. The result can then be stored in locals by equating two variables (i.e. locals.string = evaluate(parameter.name)), or by directly inserting it where I need the value.

Message 2 of 5
(4,369 Views)

Hi

 

have you ever tried to use " instead \" this show work, too

if it is neccessary to have the " in string then forget this message!

 

Regards

 

Juergen 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 3 of 5
(4,340 Views)

It depends. If you want the quotation marks to remain in the Evaluate() function then you need the \" \" to keep the values between them as a string. If you want them as parameters, then the quotation marks are unnecessary. Also, if you are saving the formula in a string parameter you need and additional set of quotes around the whole formula, but if you are entering the formula into a sequence call parameter then you leave them off.

 

Thank you for replying.

Jason

Message 4 of 5
(4,326 Views)

Hi Jason,

 

Good explanation. Thanks for sharing. 

Hope to read more answers from you in future here.

 - Time to spend another kudo.

 

Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 5 of 5
(4,320 Views)