You can use the ()-shorthand if you want to initialize an array or a part of the array with the same values.
ARRAY [1..100] OF INT :=[4(1),3(2),2(3),4]; //Equivalent [1,1,1,1,2,2,2,3,3,4]
In Codesys V3 or TwinCat 3 you can use the FB_init Method to write initialization code. The FB_init Methods of all declared FB instances will be called at startup before the normal cyclic task execution starts.
You can use it like this:
METHOD FB_Init : BOOL
VAR_INPUT
bInitRetains : BOOL; // if TRUE, the retain variables are initialized (warm start / cold start)
bInCopyCode : BOOL; // if TRUE, the instance afterwards gets moved into the copy code (online change)
END_VAR
VAR
unCount : UINT;
END_VAR
FOR unCount := 1 TO 100 DO
arrnInitExample[unCount]:= unCount;
END_FOR
Note: The first two boolean inputs of the FB_init Method have to be always the same. But you could also add additional Input variables afterwards. Then you can pass custom parameters at declaration of the FB instance to the method.