01-21-2009 01:18 AM
Hi,
Lately i was focused by colleague's a question is it possibile to run a loop within the PreExpression of a StepType.
More background: In the step there is a container, which has an array in side. The size of the array is dynamic.
Now id like to set the arrays value in the PreExpression. Good news each value of the array is the same.
but note the lenght of the array may vary form step to step!
I was not able to answer this.
I suggest to insert a StatementStep before. Get the handle to next step via RunState and do looping over the StatementStep.
Well this works. But you have one step more.
Do you think there is possibility to create an expression that is able to loop ?
Greetings
Juergen
01-21-2009 06:13 AM - edited 01-21-2009 06:15 AM
I don't know if you can effectively loop using the pre-expression, but I would avoid it. When someone debugs this sequence in the future, the looping should be obvious at first glance. I've been adding steps to some 'clever' TestStand sequences recently, and spent more time figuring out how they worked than adding my part...
"Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?'
Brian Kernighan, "The Elements of Programming Style", 2nd edition, chapter 2
01-21-2009 06:22 AM
Hi Juergen,
I dont see how you can because there is no statements such FOR/NEXT, DO/WHILE to actually structure a loop in the expression.
Can you not loop the step but on the first iteration you can size the array, then the next fill your array. Your array index will have to be one less. you can put a condition on your pre-expression or maybe do it all in the custom action loop. your total loop value will need to be one more than the size of your array.
Hope that make sense
Regards
Ray
01-21-2009
07:44 AM
- last edited on
12-03-2024
10:56 AM
by
Content Cleaner
Hi Phillip,
i agree debugging is important. But "reading" a SequeneceFile should be also easy. I have the opinion a SequnceFile and the containing
Sequences should be a mirror of the Testspecification. Every Requierement in the specification should be done at one Step ! I know this is
a great wish. Well i set my focus on this because it makes other Testprogramm writers more easy to read my stuff.
I really now this posted question is crazy. But it has real "debug" background. I have StepType (http://sine.ni.com/cs/app/doc/p/id/cs-11443) that performs DMM/ScanList every scanlist entry has a min an max value. The colleages's question was "can i override all this min/max from specifcation just by one expression during put into opertain. best in PreExpression".
I had no idea realize that. So my first choise share it with community! Maybe there is solution, i am still learning. So thanks for your answer!
( I just realized that my "2-Edition" is gone! Some has not brought it back !!!!!!)
Hi Ray,
if you do not see a way then IT IS so.
Well i also thought on step loop, but how i prevent executeing "step" the in loop? It should be executed in the last loop.
Greetings
Juergen
01-21-2009 09:16 AM
Is it a custom step?
ray.
01-21-2009 09:44 AM
I tend to agree that you should generally favor clear and obvious solutions instead of the clever and tricky.
At the same time, I like a good puzzle so I have attached a 4.0 sequence file that shows you how it can be done in an obtuse way using the Evaluate() function.
01-21-2009 03:44 PM
Eric,
Clever bit of recursive.
That Evaluate() is pretty useful.
regards
Ray
01-22-2009 01:45 AM
Hi Eric,
It took so some minutes to understand
Locals.tempExpression= "Locals.tempAssignmentString= (Locals.tempNumElements> 0) ? (Locals.tempNumElements--, \"Locals.ArrayElemValue\" + (Locals.tempNumElements> 0 ? \",\" : \"\") + Evaluate(Locals.tempExpression)) : \"\"",
but then i realized the recursion. This is pretty cool. Has Teststand any edges at all?
An other thing i have noticed is the // comments. I know that they are listed in the
expression browser but i never used them. Now seeing it in your example how you comment your expression i am absolutely sure to
use them now!
Thank you for that lesson.
Greetings from
the Lake of Constance, Germany
Juergen