ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Programatically change Enum values

I have an Enum , Enums.State with many states likeCommand1,..2, 3 etc

I want to programatically change these values with a For loop.

How to send enum variables values from an Integer ? 

 

Thanks Akshay

0 Kudos
Message 1 of 5
(2,910 Views)

Not sure if you've read through the help on this but assignment can only be done with enums of the same type: https://zone.ni.com/reference/en-XX/help/370052AA-01/tsfundamentals/infotopics/enumsastsexpressions/

 

However, you can use the SetValNumber and the coerce to enum flag:

Locals.MyEnum.SetValNumber("", 0x18, 1) where MyEnum is the enum and 1 is the numeric selection I want to make it. n 0x18 is the flag for coerce to enum:

  • PropOption_CoerceToEnum–(Value: 0x18) Use this option for implicit conversion when setting an enumeration value with a string or number. You can use this option with the PropertyObject.SetValNumber and PropertyObject.SetValString methods. TestStand ignores this flag when you specify PropOption_InsertIfMissing and the property does not exist.

 

Hope this helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 5
(2,895 Views)

Thanks a lot jigg for the answer, I will test it.

0 Kudos
Message 3 of 5
(2,875 Views)

I think Sam's answer should be marked as a solution. I'm just saying 😉

Michał Bieńkowski
CLA, CTA, CPI

  1. Did someone devote their time to help solve your problem? Appreciate it and give kudos.
  2. Problem solved? Accept as a solution so that others can find it faster in the future.
  3. Contribute to the development of TestStand by voting on the TestStand Idea Exchange.
0 Kudos
Message 4 of 5
(2,851 Views)

It doesn't work. eg:

Locals.LED_enum_as_index.SetValNumber("", 0x18, Locals.LED_index)

returns just a number.

It doesn't select the enumerated value.

 

This would work.

It's extremely verbose and long -- you can create an array with one enum value in each like this:

Locals.array[0] = [0-9.99C] (0)

Locals.array[1] = [10-19.99C] (1)

.

.

Locals.array[6] = [60-69.99C] (6)

 

But there must be a more clever way.

0 Kudos
Message 5 of 5
(2,281 Views)