Switch-case
Torbidoni
Posts: 20
Hi all,
try to compile this code with Netlinx compiler and see if you get an error (like me). If yes, WHY ??????
********************************
Netlinx Studio 2 Rel.2.3 Build 2.3.0.102
Netlinx Compiler Build 2.2.0.112
********************************
Thanks,
Fabrizio.
DEFINE_EVENT
DATA_EVENT[5001:1:1]
{
STRING:
{
IF (FIND_STRING(DATA.TEXT,"$0D",1))
{STACK_VAR CHAR resp[20]
STACK_VAR INTEGER nlin
resp=REMOVE_STRING(DATA.TEXT,"$0D",1)
nlin=ATOI(resp)
SWITCH (nlin)
{
CASE 1920:
{
}(* END CASE *)
CASE 1536:
{
}(* END CASE *)
CASE 1472:
{
}(* END CASE *)
CASE 1152:
{
}(* END CASE *)
CASE 768:
{
}(* END CASE *)
CASE 704:
{
}(* END CASE *)
CASE 640:
{
}(* END CASE *)
CASE 576:
{
}(* END CASE *)
CASE 512:
{
}(* END CASE *)
CASE 448:
{
}(* END CASE *)
CASE 384:
{
}(* END CASE *)
CASE 256:
{
}(* END CASE *)
CASE 192:
{
}(* END CASE *)
CASE 128:
{
}(* END CASE *)
CASE 64:
{
}(* END CASE *)
CASE 12:
{
}(* END CASE *)
CASE 6:
{
}(* END CASE *)
CASE 5:
{
}(* END CASE *)
CASE 4:
{
}(* END CASE *)
CASE 3:
{
}(* END CASE *)
CASE 2:
{
}(* END CASE *)
CASE 1:
{
}(* END CASE *)
CASE 0:
{
}(* END CASE *)
}// end switch
}//END IF
}// END STRING
}//END DATA_EVENT
try to compile this code with Netlinx compiler and see if you get an error (like me). If yes, WHY ??????
********************************
Netlinx Studio 2 Rel.2.3 Build 2.3.0.102
Netlinx Compiler Build 2.2.0.112
********************************
Thanks,
Fabrizio.
DEFINE_EVENT
DATA_EVENT[5001:1:1]
{
STRING:
{
IF (FIND_STRING(DATA.TEXT,"$0D",1))
{STACK_VAR CHAR resp[20]
STACK_VAR INTEGER nlin
resp=REMOVE_STRING(DATA.TEXT,"$0D",1)
nlin=ATOI(resp)
SWITCH (nlin)
{
CASE 1920:
{
}(* END CASE *)
CASE 1536:
{
}(* END CASE *)
CASE 1472:
{
}(* END CASE *)
CASE 1152:
{
}(* END CASE *)
CASE 768:
{
}(* END CASE *)
CASE 704:
{
}(* END CASE *)
CASE 640:
{
}(* END CASE *)
CASE 576:
{
}(* END CASE *)
CASE 512:
{
}(* END CASE *)
CASE 448:
{
}(* END CASE *)
CASE 384:
{
}(* END CASE *)
CASE 256:
{
}(* END CASE *)
CASE 192:
{
}(* END CASE *)
CASE 128:
{
}(* END CASE *)
CASE 64:
{
}(* END CASE *)
CASE 12:
{
}(* END CASE *)
CASE 6:
{
}(* END CASE *)
CASE 5:
{
}(* END CASE *)
CASE 4:
{
}(* END CASE *)
CASE 3:
{
}(* END CASE *)
CASE 2:
{
}(* END CASE *)
CASE 1:
{
}(* END CASE *)
CASE 0:
{
}(* END CASE *)
}// end switch
}//END IF
}// END STRING
}//END DATA_EVENT
0
Comments
- Chip
Yup, there is something flakey with the compiling of SWITCH CASE and I think Chip is on the right track but there is more to the story I think. If you take your original posting and reverse the CASE statements so that they are in ascending order (CASE 0: first ? CASE 1920: last) then it will compile fine.
And just to verify try compiling the next two examples. The first compiles fine, the second has issues:
Something sure doesn't seem right. I usually stick with SELECT ACTIVE mainly because it?s more flexible even though it?s more verbose in some situations.
Hope this helps.
HTH.