From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Create If Flow Control Step with .NET API and set condition

Solved!
Go to solution

Hello,

I figured out how to create the "If" and "End" steps, but I can't find out how to set the conditional expression for the step. Can someone please tell me how to do that? Also, do I need to configure the end step in any way, like linking it to the if step, or does the if step simply jump to the next end step if the expression evaluates to false?

 

Thanks in advance!

0 Kudos
Message 1 of 3
(2,120 Views)
Solution
Accepted by topic author therealmaxmustermann

Your assumption about the end step is correct.  It just needs to match the nesting.  Similar to curly braces in C# or other languages.

 

Assuming Locals.Step is a reference to the IF step you can do: Locals.Step.ConditionExpr = "True" 

If the conditional is stored in a local variable then you need to do: Locals.Step.ConditionExpr = "Locals.MyCondition"

 

If you can't get access to ConditionExpr like that then you do Locals.Step.SetValString("ConditionExpr", 0x0, "True") or Locals.Step.SetValString("ConditionExpr", 0x0, "Locals.MyCondition") 

 

Setting expressions are different than setting strings.  You almost have to have the mindset that you are one layer removed.  So it needs to be a string but the output needs to be able to be evaluated.

 

Hope this helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 2 of 3
(2,088 Views)
Solution
Accepted by topic author therealmaxmustermann

Thanks for your reply.

I actually could figure out how to do this. I was struggling at first because I didnt realize I had to set a Property in the PropertyObject.

I am using C# for my project, and I tried setting the Expression like this:

myStep.ConditionExpr = "True";

But this does not work in C# since ConditionExpr is no Member of Step.

To set the Property in the PropertyObject I did this:

myStep.AsPropertyObject().SetValString("ConditionExpr", 0, "True");

Your answer is totally correct and I can see where you're coming from, but if I didn't know about the PropertyObject maybe I'd struggle to get from your answer to working C# code. If someone in the future stumbles upon this, I hope it'll help them. 🙂

0 Kudos
Message 3 of 3
(2,086 Views)