04-29-2010 12:03 PM
Here is a Csharp code snippet that I thought should work, but doesn't:
...
PropertyObject item;
...
if (item.GetValString("TS.StepType", 0) == "NI_MultipleNumericLimitTest")
{
string lowerBound, upperBound;
int numElements;
PropertyValueTypes elementType;
item.GetDimensions("Measurement", 0, out lowerBound, out upperBound, out numElements, out elementType);
for (int k = 0; k < numElements; ++k)
{
// **** This next line throws an exception - "Specified value does not have expected type"
PropertyObject arrayEntry = (PropertyObject)item.GetValVariantByOffset(k, 0);
if (arrayEntry.Exists("Status", 0))
{
this.currentResultData.status = arrayEntry.GetValString("Status", 0);
}
...
}
}
Solved! Go to Solution.
04-29-2010 12:41 PM
I figured it out...
item.GetDimensions("Measurement", 0, out lowerBound, out upperBound, out numElements, out elementType);
...
PropertyObject arrayEntry = (PropertyObject)item.GetValVariantByOffset(k, 0);
... should be ...
PropertyObject measurementProperty = item.GetPropertyObject("Measurement", 0);
measurementProperty.GetDimensions("", 0, out lowerBound, out upperBound, out numElements, out elementType);
...
PropertyObject arrayEntry = (PropertyObject)measurementProperty.GetValVariantByOffset(k, 0);
04-30-2010 09:22 AM
It's probably better to call GetPropertyObjectByOffset instead of GetValVariantByOffset, then you won't need the cast and will give a better error message if it's not an array of objects.
-Doug