Switch Case statement Doubts
John Paul
Posts: 143
I am facing a compiler error when i run the commented sections of the code in the axi file which i have attached in this post.
I want to run a switch case where each case will be integer values or char values in a structure array. I am getting the following errors, if anyone has a workaround i will be thank full . If else statements compile fine.
ERROR: C10591: CASE value is not a constant
0
Comments
Im no guru (really Im just beginning but I'll have a crack). It seems to me that the value after the CASE keyword needs to be a constant not a variable as it is in your file. I believe this is the same as the switch-case in Java.
Morris
I'd probably stick GET_LAST(nHVAC2FKLRBtn) into a variable first so it's not re-evaluating every time.
For example , CASE uHVAC[2].nSetTemp: . This case is same as CASE nSetpointTemp:, which compiles properly.
When you put variables in the case statement it is built with whatever value that variable is at startup.
You *must* have a constant, non-variable thing to compare against when evaluating ANYTHING - again, not just in code. You can't compare an apple to an orange if the apple can be a grape sometimes.
While I always try to push the bounds of NetLinx, in this case I suggest you try re-evaluating your programming logic instead of the nature of how NetLinx works.
I agree with this sentiment. Usually when I find myself raging against the machine that is Netlinx, I really need to rethink how I am approaching the problem. The sooner I push myself through this process the sooner I can get on with something useful.