I can easily do the following:
arrIndicatorColor : ARRAY[1..5] OF STRING;
arrIndicatorColor := 'Red';
arrIndicatorColor := 'Yellow';
arrIndicatorColor := 'White';
I'd prefer to set all the values of the array with a single line.
arrIndicatorColor := ['Red','Yellow','Green','Blue','White'];
However this line of ST gives me an error "Unexpected array initialization". Is there a proper syntax? I can copy and paste, in my example it's only 5 array elements but if this was 10 elements with 10 cases, it becomes a lot of lines of ST.
I have no problem with STRING vs WSTRING...just a typo since I'm not in the CODESYS IDE, changed to reflect. I don't want to initialize the array with certain values. I want to set all elements of the array using one line of ST.
Here is how that should look for initializing it with those strings
arrIndicatorColor: ARRAY[1..5] OF STRING := ['Red', 'Yellow', 'Green', 'Blue', 'White'];
The difference between yours and mine is you used " which indicates a wString and ' which indicates a String.
Sorry at first I specified that address 1 was Red and address 2 was Yellow but that didn't work past Red. In case you're wondering if you want to initialize only part of the array it would look like this.
arrIndicatorColor: ARRAY[1..5] OF STRING := ['Red', 'Yellow', 'Green', 2('')
You can also use the input assistant and within that the array wizard to have it spit out an array variable with specific formating if you aren't sure how it should look.
Log in to post a comment.