Twincat 3 error then use string as variable name

r142dm

Member
Join Date
Jun 2018
Location
Hestra
Posts
2
Hi!


i try to use string as variable name in a forloop my problem is tahat my if insturktion not allow strings as variable name.


my declaration is


var



aForSend : ARRAY [1..3,1..6] OF STRING;

bSmsNr1InUse : BOOL;
bSmsNr2InUse : BOOL;
bSmsNr3InUse : BOOL;
bSmsNr4InUse : BOOL;
bSmsNr5InUse : BOOL;
bSmsNr6InUse : BOOL;


k: INT;


end_var


program



FOR k:=1 TO 6 BY 1 DO

IF (concat('bSmsNr',concat(INT_TO_STRING(k),'InUse'))) THEN
aForSend[3,k]:='1';
ELSE
aForSend[3,k]:='0';
END_IF
END_FOR



i get error cannot convert type string (255) to type bool


//Dennis
 
You cannot use concat in IF statement condition. It has to be boolean result. Thats why you got that build error.
Do the concat before IF statement and use comparison in the condition.
And in twincat you don't have to use ; in the end of statements.
 
Last edited:
What i mean IF (concat('bSmsNr',concat(INT_TO_STRING(k),'InUse')) ) THEN the result is STRING, it should be something like this IF (concat('bSmsNr',concat(INT_TO_STRING(k),'InUse')) ) = STRING_VARIABLE THEN then the result is boolean.

If you are trying to check if some of bSmsNr variables are true and then write it to string table as true, its way easier to declare bSmsNrInUse as an boolean array.
Code:
VAR
     aForSend : ARRAY [1..3,1..6] OF STRING;
     aSmsNrInUse : ARRAY [1..6] OF BOOL;
     k : INT;
END_VAR

FOR k:=1 TO 6 BY 1 DO

IF aSmsNrInUse[k] THEN
    aForSend[3,k]:='1';
ELSE
    aForSend[3,k]:='0';
END_IF
END_FOR
 
Last edited:

Similar Topics

Sorry if this has been asked before, and apologies if this seems like a trivial issue, but I am new to Beckhoff and have been banging my head...
Replies
2
Views
154
Gents, I'm trying get some SEW Movigear motors in control by a Beckhoff PLC which is TwinCAT 3. The SEW motor is connected by EtherCAT and is...
Replies
0
Views
1,310
Gents, I'm pretty new to Twincat 3 and facing at an annoying issue when try to go online with a remote Beckhoff PLC. At out plant we have 10...
Replies
5
Views
4,674
Hello: I have a TwinCAT embedded PLC and for years I was able to access it through the AMS NetID. Recently updated Windows 10 and I was not able...
Replies
6
Views
16,228
I am trying to get the TwinCAT Master running on a Windows 10 PC, but cannot make it run, except in the Config mode. When I try to change it to...
Replies
2
Views
7,480
Back
Top Bottom