0

Structured text seems to delight in making the simple really difficult (much more used to C). Could somebody please rearrange this so it will compile.

VAR_GLOBAL ErrorStg : Array[0 .. 10] of STRING[16] := "Good","Bad","Fsked"; END_VAR

2 Answers2

1

Did you read the compiler error at all...?

The working version at least on CODESYS 3 based platforms:

ErrorStg : ARRAY[0 .. 10] OF STRING[16] := ['Good','Bad','Fsked']; 

The working version at least on CODESYS 2 based platforms:

ErrorStg : ARRAY[0 .. 10] OF STRING[16] := 'Good', 'Bad', 'Fsked'; 

You should use ' instead of " with regular strings.

Quirzo
  • 1,183
  • 8
  • 10
  • Thanks. I should have mentioned the version , which is Schneider EcoStruxure, tho I believe its roots are in Elliwell. No, this doesn't work for me, giving an "Invalid init value". I'm not a StackOverflow regular, so the formatting is escaping me. – Lonesome Twin Mar 31 '22 at 13:56
  • Does the system have a help? Usually the PLC systems have quite nice help documentation. One solution is to try `:= 'Good', 'Bad', 'Fsked';` which is valid for CODESYS 2 based systems (so no brackets). – Quirzo Apr 04 '22 at 06:46
0

When you initialize an array on the definition line, you have to give all of the values (all 11 in your case).

As an alternative, I would suggest a much easier solution - use an init routine to assign the values. If you are opposed to “burning boot time”, you can still solve by defining a FB called InitGlobals and then define a FB_INIT method and put your assignments there. FB_INIT executes as soon as the object exists and not when your program runs. Add an instance of InitGlobals to your code, of course.

Scott
  • 116
  • 2
  • Actually at least CODESYS 2 & 3 based systems don't need all values. You can initialize array with just few values. – Quirzo Apr 04 '22 at 06:50