How to use Enumerators in Sysmac Studio
Enumerators are a custom data structure of named constants for integers. These assist in making your code more readable and is typically used when a list of predefined inputs/outputs are needed.
Creating Enumerators
To create an enumerator perform the following steps:
- In the Multiview Explorer tab go to Programming → Data → Data Types
- Click Enumerated on the left side of the main Edit Pane
- Right click the main edit pane area and select create New Data Type
- After giving your enumerator a name right click and select create New Member
- Name and give an enumerator value to the member
- Repeat steps 4 and 5 as necessary

How to Assign Enumerators
There are two methods to set an enumerator manually if needed.
Converting an Int
The first method would be to use the NumToEnum function.

As can be seen by applying the correct integer value we can select our desired value of the enumerator.
Directly Assigning the Enumerator
You can also directly assign the enumerated value using the following syntax:
<Name of enumerator data type>#<Enumerated value>

Comparing Enumerators
Occasionally you may find that you need to compare the data in an enumerator to determine its state.
A good example of this would be interpreting the output of the GetDayOfWeek Function. As we can see from the documentation the output is an enumerated data type

Since we cannot directly compare this to a string or Integer as there would be a mismatched we would either need to directly compare the enumerated value or convert the enumerated value to be compared.
Converting the Enumerator
The first method we could do is use the EnumToNum function to convert the enumerator into a double Int. From our example above Tuesday is 2 on the enumerator table so therefor would be converted to 2.

Directly Comparing the Enumerator
We can also directly compare to the enumerated value using the following syntax:
<Name of enumerator data type>#<Enumerated value>
This is demonstrated in the example below.
