NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Get the Nth variable in a container

Hello,

 

Can you tell me how I can get the Nth variable in a container?

 

I've tried accessing it using PropertyObject's mehods, but PropertyObject only has methods to get the name of the nth variable (or array).

 

How can I access the variables I have in a container, programmatically, like the way you get the next element in an array?

 

Thanks,

Naeemeh

0 Kudos
Message 1 of 13
(5,119 Views)

PropertyObject.GetNthSubProperty

 


0 Kudos
Message 2 of 13
(5,112 Views)

I'm using ActiveX action to be able to use PropertyObject's methods, and it doesn't

show me this method in the drop down menu. It has GetNthSubPropertyName but not GetNthSubProperty.

 

The attached picture shows the functions I have available.

 

Thanks,

Naeimeh

0 Kudos
Message 3 of 13
(5,111 Views)

Hi

 

This code snipped shows

How i will iterate through an array of strings.

 

pObjArray->GetDimensions ("", 0, &bstrLowerBounds, &bstrUpperBounds, &lNumElements, &enType);
if(enType == PropValType_String && lNumElements > 0){
 for( LONG i = 0; i < lNumElements; i++){
  strLookup.Format("[%i]",i);
  strLine = (LPCTSTR)_bstr_t( pObjArray->GetValString(_bstr_t(strLookup), 0));
  strLine += "\n";
  StdioFile.WriteString(strLine);
 }
}

 

 

Note: Here i am acessing through the index. This will work for every kind of container

Maybe this helps.

 

Regards

Juergen

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

Hi

 

notice you are using TS 3.5, therefore you will need to use

GetNumSubProperties and then index through using GetSubPropertyIndex or possibly GetNthSubPropertyName until you find the property you require.

 

 

Regards
Ray Farmer
0 Kudos
Message 5 of 13
(5,081 Views)

Hi Juergen,

 

Thanks alot for the code 🙂

 

So just to make sure, the code you've written is in C and I need to use the C/C++ DLL to add it

to my TestStand sequence, right? I can't just write it in a Statement step in TestStand, right?

 

 

Thanks for you help,

Naeemeh

0 Kudos
Message 6 of 13
(5,065 Views)

And another issue.

 

I have 16 arrays in my container and I need to get these arrays one by one. I know the dimensions

of the container.

There are methods to get numbers, strings, etc. (like the one you used GetValString()) but the is no function to

get an array, like GetValArray(). 

 

What I'm looking for is a way to write something like below:

 

for(each array in MyContainer)

 

for(each element in the array)

//Do Something

 

end

 

end

 

Thanks,

Naeemeh

0 Kudos
Message 7 of 13
(5,064 Views)

Hello,

 

Thanks for the suggestions but none of those mehods give me the properties.

GetNumSubProperties tells me how many properties there are and  GetNthSubPropertiesName gives me their names??

 

Thanks,

Naeemeh

 

 

0 Kudos
Message 8 of 13
(5,063 Views)

For properties use the names you get from GetNthSupropertyName with GetPropertyObject as the lookup string parameter for that method.

 

For arrays use GetNumElements(), then GetValStringByOffset/GetValNumberByOffset/etc. depending on the type of your array by using the offset as an index from. For example:

 

int numelements = myarray.GetNumElements();

for(int i = 0; i < numelements; i++)

{

    double elementval = myarray.GetValNumberByOffset(i, 0);

}

 

NOTE: You can also get an entire array at once using GetValVariant(), however that can be very hard to deal with depending on the programming language you are using as it will return a variant that contains a safearray.

 

Hope this helps,

-Doug

0 Kudos
Message 9 of 13
(5,053 Views)

GetNthSupropertyName gives me the name of the array that I have in my container.

What I want to do is to get the array itself which is inside my container.

0 Kudos
Message 10 of 13
(5,049 Views)