"Foreach" ATEasy equivilant for enums

Sadiq H.
High Wycombe, BUKS

Feb 1, 2019
2 Posts

0  |  0  

Re: "Foreach" ATEasy equivilant for enums

Hi,
I am new to ATEasy and still learning the syntax and its function, etc. I have a question with regards to Enums in ATEasy. Lets say I have an enum which has 10 different values:

eMyEnum:
{
a = 0x103
b = 0x113
c = 0x123
d = 0x133
e = 0x143
f = 0x153
g = 0x163
h = 0x173
i = 0x183
j = 0x193
}

is there a way to have a loop like a "FOREACH" function that would check if an integer "x" has any of the above enum values?

instead of having a lot of "if" statements or a long if statement like:
if (x = eMyEnum.a or x = eMyEnum.b or .........) then

I am asking this as in the future this enum size will increase and i want to have a function that can adapt to it.

Thanks,
Sadiq

DrATEasy (Ron Y.)
Mission Viejo, CA

Feb 1, 2019
358 Posts

0  |  0  

Re: "Foreach" ATEasy equivilant for enums

There is no 'foreach'. You can use a select statement instead of the if that:

select x
case eMyEnum.a, eMyEnum.b
...
case eMyEnum.c to eMyEnum.f, eMyEnum.j
...
case else
...
endselect

Sadiq H.
High Wycombe, BUKS

Feb 4, 2019
2 Posts

0  |  0  

Re: "Foreach" ATEasy equivilant for enums

Hi Ron,

Thanks for your feedback.

The switch case will still need to be updated by adding and checking the new elements added in the Enum later on. What I was trying to ask was, is there a way to check if the value of 'x' is equal to any of the Enum elements without knowing how many and what are the Enum elements. Like an Array, where you can do:

for i=0 to sizeof(Array) do
if (x = Array[i]) then
.......
endif
next

Maybe using an Enum isn't the correct way to do this. I just wanted to see if ATEasy had a method that deals with Enums in that way.

Thanks,
Sadiq

DrATEasy (Ron Y.)
Mission Viejo, CA

Feb 6, 2019
358 Posts

0  |  0  

Re: "Foreach" ATEasy equivilant for enums

There is no built-in to check if a value is a member of an enum . However, there are other methods. For example you can add to the description of the enum, retrieve the description using DescOf operator and and search for them (using Pos). Another way, if the values are small numbers, you can create an array of bool to say what values are valid.



Please Note
You need to have a M@GIC account to participate in the Forums.
Not yet registered on our website? Click here to register today!

All content, information and opinions presented on the Marvin Test Solutions User Forums are those of the authors of the posts and messages and not Marvin Test Solutions'. All attachments and files are downloaded at your own risk. [Read More]