Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched.
Close
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2016-06-22
Originally created by: scott_cunningham
Sorry Volvo742, I never get emails from this BBL anymore. Something blocks them.
I made a typing mistake - I meant to use INT_TO_STRING and then iterate through each char of the string and go STRING_TO_INT. Like this:
PROGRAMPLC_PRGVAR
  Start : INT :=5432;
  Result : ARRAY[0..9] OFINT;END_VARVAR_TEMP
  J : INT;
  Str : STRING;END_VARStr :=INT_TO_STRING(Start);FORJ :=0TOLEN(Str)DO
  Result[J] :=STRING_TO_INT(MID(Str,1,J+1));END_FOR
Of course, putting this as a FUNCTION would be better...
A little faster FOR LOOP solution (MID may be slow and one shouldn't put any calculations in the FOR line as it calculates every time it loops):
PROGRAMPLC_PRGVAR
  Start : INT :=5432;
  Result : ARRAY[0..9] OFINT;END_VARVAR_TEMP
  J : INT;
  Str : STRING;
  Chars : INT;END_VARStr :=INT_TO_STRING(Start);Chars :=LEN(STR)-1;FORJ :=0TOCharsDO
  Result[J] :=BYTE_TO_INT(Str[J]-48);END_FOR
Indexing in a string returns a byte data type, which happens to be the ascii code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello.
Is it possible to split int to int array?
For example int value 5356 to 5, 3, 5, 6?
You could do it with a FOR loop and some modulo instructions.
Thank you! That solve my problem.
Originally created by: scott_cunningham
Additionally, you can use INT_STRING and then grab each char and use STRING_TO_INT until end of string.
Thank you. You men i use indexing?
Example :
var2: INT_STRING := 6367;
var1: STRING;
var1 := INT_TO_STRING (var2 [0]); // first number
Originally created by: scott_cunningham
Sorry Volvo742, I never get emails from this BBL anymore. Something blocks them.
I made a typing mistake - I meant to use INT_TO_STRING and then iterate through each char of the string and go STRING_TO_INT. Like this:
Of course, putting this as a FUNCTION would be better...
A little faster FOR LOOP solution (MID may be slow and one shouldn't put any calculations in the FOR line as it calculates every time it loops):
Indexing in a string returns a byte data type, which happens to be the ascii code.