LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

learning exercise, modifying coke machine example

I've been using LabView part time for the last 6 months and am still learning. As a self imposed exercise, I tried to modify ni.com's state machine example, the coke machine, to accept an additional coin. It seemed like it would be an easy exercise, but I really struggled with it and spent more time than expected. After a lot of hacking, I found out that adding "halfdollar' to the end of an enum or case statement works, but trying to insert after "Quarter" seems to make things a mess. Why can't I insert a new enum/case in the middle or what was I doing wrong?
 
I'm using version 8.2.
0 Kudos
Message 1 of 3
(2,681 Views)
You can, you just need to be careful. That example, unfortunately, is a perfect example of how not to create an enum for state machine control. The enumeration should be a typedef. As it is, you need to change the enumeration's list of items in many places so they all match. If it were a typedef then you would only change it one place. So, a better exercise for you would be to first replace the enumeration constants by creating an enumeration typedef. Then, verify the VI works like the original. Then, modify the typedef to add your state and then all you would need to do is to add the additional case to correspond to this new enumeration item.
Message 2 of 3
(2,669 Views)
Thanks smercurio, I was also wondering if there was a maintianability flaw, so you also answered that question. I have Blume's Style book on order, so I'm looking forward to reading his tips.
0 Kudos
Message 3 of 3
(2,640 Views)