12-16-2010 12:05 PM
@~jiggawax~ wrote:
@"Next question: Is there a TestStand function for searching array elements or do I need to use ForEach?"
You can loop on a statement step. That's generally what I do if I need to access each element in the array. Or pass it to a code module and have the code module do the work for you.
I've seen sequences with over 1,000 steps in them. I think that too many people try to use TestStand as a programming language and don't utilize code modules enough.
The problem in your case of a straight search is that like you said earlier.... You will have to account for every Rev that is beyond a certain point. That way you won't have to add every single rev in your file or list of PNs.
In my example I incorporated the ability to set a rev and allow it to be a greater than rev. If you look in the file you will see a line that starts with "> " This means that anything matching that PN and has a rev greater than or equal to the rev on that line then make it so thos PNs skip the steps too. The file can be added to or deleted from.
`~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Yep, didn't see it at first glance, then I saw the Rev input. Then I realized (quicker than I expected, must be learning to recognize LV components and idioms) that you were handling the Greater Than case. I was working toward this as one solution but you were much faster than me. Also I kept going back and forth in my feeble mind - "Do it in TS or do it in LV?".
Thanks again, this is some of the fun stuff.
12-16-2010 12:10 PM
@dug9000 wrote:
@jvh75021 wrote:
Next question: Is there a TestStand function for searching array elements or do I need to use ForEach?
If you create an array of containers and make the names of the containers your model number strings, then you can effectively check if something is in the array by doing:
PropertyExists("Locals.ModelsToExclude[\"" + Locals.CurrentModelName + "\"]")
If your module names can have special characters like quotes or backslashes in them, you will need to do this instead (or you can just do this anyway just incase):
PropertyExists("Locals.ModelsToExclude[" + RunState.Engine.Utility.Escape(Locals.CurrentModelName, EscapingOption_SurroundedByQuotes) + "]")
Hope this helps,
-Doug
Thanks Doug, this too is interesting. I was thinking it would be more like StringExists or StringFound. Didn't strike me as being a property.
I might have to do it your way and jigg's way just for the satisfaction and learnin' opportunity.
12-16-2010 12:12 PM
Doug,
Can you get the element index from that though? just curious.
12-16-2010 01:14 PM
You can, but you don't really need to know the index in most cases. If you just want to access subproperties of the element you can do the following:
Locals.ModelsToExclude[Locals.CurrentModel].Mysubproperty
Being able to add extra data (i.e. subproperties) to the elements because they are containers is also a nice benefit of this approach.
To get the array index or array offset if you absolutely need it for some reason, you can do the following:
Locals.arrayOffset = Locals.ModelsToExclude.GetArrayOffset("", 0, "[" + RunState.Engine.Utility.Escape(Locals.CurrentModel, EscapingOption_SurroundedByQuotes) + "]"),
Locals.arrayIndices = Locals.ModelsToExclude.GetArrayIndex("", 0, Locals.arrayOffset)
Hope this helps,
-Doug