iTest : int;wTest : word;FORiTest :=1TO10DO
  wTest :=PutBit_W(wTest, iTest, TRUE); (* to set the bit iTest *)
  wTest :=PutBit_W(wTest, iTest, FALSE); (* to clear the bit iTest *)END_FOR
This will work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
To add you can also use constants as bit modifiers but you also have to select in the OPTIONS-BUILD-REPLACE CONSTANTS. So you can do the following:
options:word;varconstant OPTION1:word:=0; OPTION2:word:=1; ON     :BOOL:=TRUE; OFF     :BOOL:=False;end_varoptions.OPTION1:=ON;options.OPTION2:=OFF;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've got a question about bit addressing in Codesys 2.3.9.18:
I would like to use the following code:
This returns the error:
Integer number or symbolic constant expected
The following example does work:
Is it possible to use something like 'wTest.iTest'?
(and yes, it is possible to use an ARRAY OF BOOL to store a large collection of booleans, but this uses a lot more memory)
I only could suggest to use a function, which gets the bit number as an input.
http://www.geisler-controls.de I've published the library BinUtils. Use the function PutBit_W out of it :
This will work.
Thanks for your reply. You put me on the right track. A library I'm already using (util.lib) also has a function PUTBIT. The program works now.
To add you can also use constants as bit modifiers but you also have to select in the OPTIONS-BUILD-REPLACE CONSTANTS. So you can do the following: