First of all your example is very strange. Confition IF
will work in every cycle and it is not clear how condition depends on cycle. I think you mean.
IF toCheck = i THEN
Anyway, in codesys you cannot do something like in PHP Variable variables
$a = "hello";
$$a = "world";
echo $helo // output world
Or like this
$b = 2;
$a1 = 1;
$a2 = 2;
echo ${"a" . $b}; // Output 2
Those all will not work in ST. You have use different aproach. If you would tell in your question the final task you want to solve, I would suggect you the best, but now I'll give you only general idea. All examples for Codesys 2.3. In 3.5 there is slightly different syntax.
- Arrays
VAR
aSteps: ARRAY[1..4] OF INT := 1, 2, 3, 4;
END_VAR
toCheck := 3; // INT
result := 0; // INT
FOR i := 1 TO 4 DO
IF toCheck = i THEN
result := aSteps[i];
END_IF
END_FOR
But even simplier, as you already know index with toCheck
and you do not need to convert it to variable name, you can simply.
VAR
aSteps: ARRAY[1..4] OF INT := 1, 2, 3, 4;
END_VAR
toCheck := 3; // INT
result := aSteps[toCheck];
- Enumerations
First you define a type.
TYPE enSteps : (
stepIdle, stepStart, stepEnd := 5
);
END_TYPE
Now stepIdle := 0
, stepStart := 1
and stepEnd := 5
VAR
result: enSteps;
END_VAR
toCheck := 1;
result := toCheck;
IF result = stepStart THEN
// DO something
END_IF
or you can use CASE
CASE result OF
stepIdle: // do something
stepStart: // do something
stepEnd:
result := stepIdle;
END_CASE
Remarks
If you would deccribe what you are trying to achieve, I would give you a better suggestion.