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 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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).
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.

1 Comment

Actually at least CODESYS 2 & 3 based systems don't need all values. You can initialize array with just few values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.