From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Enums containing spaces in expressions in TestStand 2016

Solved!
Go to solution

Hi, just upgraded to TestStand 2016f1 today. Smiley Happy

So I created a typdef Enum in LabVIEW.  The enum had mutlple words with spaces for a value.

I then called the VI from the teststand adpator and clicked the Create/Update Custom Date Type from Enum button.

All good so far.  But now I want to use the enum in the expression. 

Locals.myEnumVal==Enums.myEnumName.firstword secondword 

I get an unexpected token syntax error on secondword. 

If I look at http://www.ni.com/white-paper/52330/en/#toc3 I note it has quotes in the value column, where my enum has a value of

[firstword secondword] (0)

where (0) is the enum constant. 

 

 

How is this supposed to work? I can't find an example. Help doesn't cover spaces. I.e no examples for a color "light blue". E.g.

locals.myFavoriteColor==Enums.Color.Light Blue

- how do we get this to work?...Smiley Frustrated I assume its something obvious I have overlooked. 

 

http://zone.ni.com/reference/en-XX/help/370052R-01/tsfundamentals/infotopics/usingenumstsadapters/

http://zone.ni.com/reference/en-XX/help/370052R-01/tsfundamentals/infotopics/enumsastsexpressions/

http://zone.ni.com/reference/en-XX/help/370052R-01/tsfundamentals/infotopics/gettingstartedcreatinge...

 

Cheers.

 

0 Kudos
Message 1 of 8
(5,801 Views)

Try the Enum() expession function - it's mentinoed in the help topic you linked.

Spoiler
Enum(String type, [String|Number] value) — Returns an instance of an enumeration with the specified type and value. If value is a string, the enumerator and number are set as if by calling SetValString(). Passing an out of range value results in an error. If value is a number, the value is set as if by calling SetValNumber(), SetValInteger64(), SetValUnsignedInteger64() as appropriate for the representation of the enumeration type. Passing an out of range value to a strict enumeration results in a runtime error.

Hope this helps!

Trent

https://www.linkedin.com/in/trentweaver
Message 2 of 8
(5,779 Views)

Hi Trent

thanks for your reply. I found that and still couldn't figure out what it wanted or how to make it work.

 

Locals.myFavoriteColor==Enum(Enum.Color,Enums.Color.light blue) still gives an unexpected token. 

 

Locals.myFavoriteColor==Enum(Enum.Color,"Enums.Color.light blue") - could not find type ".

 

To me the whole point of the enum is to be able to type Enums. {Prompt for defined enum names...} . {prompt for value string}

 

So for the color example how to get it to work? 

0 Kudos
Message 3 of 8
(5,763 Views)

Pictures...

color enums with spaces.png

color expression.png

0 Kudos
Message 4 of 8
(5,756 Views)
Solution
Accepted by topic author NickNZ

The Enum() method is expecting a string for the first input as well, try:

Locals.myFavoriteColor=Enum("Color","light blue")

or

Locals.myFavoriteColor=Enum("Color",3)

I understand what you mean about the auto complete issue, and there is actually already a CAR (612847) in place improve the auto complete usability for enums.

 

Hope this helps!

Trent

https://www.linkedin.com/in/trentweaver
Message 5 of 8
(5,750 Views)

Thanks a lot  for your help Trent, at least I can progress now....

I tried Locals.myFavoriteColor == Enum(Enums.Color,"Dark Blue") Error is expected type String Found type (Enum) Color.

Locals.myFavoriteColor == Enum("Enums.Color","Dark Blue")  also fails as cannot find type Enums.Color.....

 

Lets say its not that intutive and misses the point of autocomplete alltogether. Autocomplete is currently miss-leading users down the wrong path as well.  I look forward to the CAR being completed. 

0 Kudos
Message 6 of 8
(5,740 Views)

Hello Nick,

 

I know you probably found an answer by now, but I wanted to give an answer in case someone else runs across this.  We have a similar situation.

 

I believe the code needed is 

 

Locals.myFavoriteColor = Enum("Color","Dark Blue")

 

I apologize.  I see you did get the answer earlier.

Message 7 of 8
(5,170 Views)

Hello,

 

I am using TS2017 and the same problem occurs. 

Is there new workaround avaliable?

 

There is moe scenarios with this breaks, for example when typing 

Enums.MyEnum.%s%d

0 Kudos
Message 8 of 8
(3,878 Views)