Internet PLC Forum
General => Technical support => Topic started by: garysdickinson on October 22, 2014, 10:39:08 AM
-
OK, you added a new "keyword", #defineLocal. How do you use it?
- The text "#defineLocal" is highlighted by the syntax highlighter.
- Clicking on #defineLocal" does not bring up any "keyword helps"
- #defineLocal" is not in the list of "keyword helps"
- The TL7ReferenceAddendum.pdf mentions the #defineLocal, but gives no hint or example of how to use it.
Ok. So I'm taking guesses. I wrote the following custom function (one of a series of tests):
#defineLocal ILocal %[1]%
For ILocal = 1 to 10
print #1 ILocal
next
[/color]
I wrote ladder logic that could invoke the custom function (I know about the compiler optimization for orphaned functions).
If I run the "Compile Only" option, the code compiles without complaint (no syntax error).
If I comment out the #defineLocal line, the code fails to compile (as it should). This suggests that my usage of the #defineLocal is pretty close to what the compiler expects.
If I click on the "Run (All I/O Reset) menu, the simulator does not run and no error messages are presented. The presence of #defineLocal breaks the simulator!
OK. So how was this #defineLocal supposed to be used?
Gary D.
-
I copy the comments in the sample program "definelocal.pc6" which should be in the "usr\samples" folder. A copy is attached.
Starting from i-TRiLOGI version 6.46 build 03, besides using the #Define table you can also define
label names that only has local scope by using the #defineLocal labelname = expression.
E.g. #defineLocal RoomTemperature = DM[100]
You can then freely use the label name "RoomTemperature" within this custom function in place of
DM[100] so that the program is more readable.
The #defineLocal keyword is useful if you only want the labels to be valid in the current function.
It could make it easier to create a library function that you can re-use in other applications
without exporting and importing the #Define table.
Note:
------
1) The compiler will first process any label names defined using the #defineLocal before it processes
the #Define table. So if a label name that is defined by the #definelocal label will be
preprocessed first.
2) Unlike the #Define table the program does not conduct a check on whether you have
duplicated #defineLocal on the same label, or whether a label so defined is a reserved keyword.
So the programmer must exercise greater care when using #defineLocal to avoid ending up with
hard-to-debug compilation errors.
-
Thanks for the hint on #defineLocal syntax.
I was able to use something like this to create a variable that was local to a custom function with V7:
#defineLocal ILocal = %[1]
Please look at the issue of the compiler, not complaining about incorrect syntax for #defineLocal and the Simulator crashing without an error message for a future release. These behaviors are sort of rude.
Thanks,
Gary D.
-
Thank you for the reminder. We will look into what causes the compiler to fail when wrong syntax is used for #definelocal statement.