Detail: array values are 1 or 0
In the theory the value of valuetotal should be 0 to 255,
But when I read the value of In valuetotal it is always shown 0
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think the problem you are having is due to myarray() being a byte and valuetotal being a bit.
Maybe if you put valuetotal.0=myarray(1).0 it would maybe work. Or...
k=1
for i=1 to 8
if myarray(i) > 0 then valuetotal=valuetotal+k
k=k*2
next i
Last edit: David Stephenson 2016-11-24
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I use bit-wise assignments similar to this quite a lot. Are you saying that I need to be more careful as unexpected things can happen? I've picked out a particularly ugly piece of code that is part of my driver for an e-paper display which works.
@David. I am assuming you are on v.0.95.010
@Fábio Almeida ... I am thinking you are not on v.0.95.010. Let us know. As the code below works correctly (prints 32). Also, which chip?
I want to get the total value of an array, how do I do this?
I already tried to do this, it did not work:
Dim valuetotal as byte
Dim myarray(8)
valuetotal.0 = myarray(1)
valuetotal.1 = myarray(2)
valuetotal.2 = myarray(3)
valuetotal.3 = myarray(4)
valuetotal.4 = myarray(5)
valuetotal.5 = myarray(6)
valuetotal.6 = myarray(7)
valuetotal.7 = myarray(8)
Detail: array values are 1 or 0
In the theory the value of valuetotal should be 0 to 255,
But when I read the value of In valuetotal it is always shown 0
Use Setwith method. This will sort this.
I think the problem you are having is due to myarray() being a byte and valuetotal being a bit.
Maybe if you put valuetotal.0=myarray(1).0 it would maybe work. Or...
Last edit: David Stephenson 2016-11-24
The FAQ in the Help shows why this cannot work. The SetWith method will resolve.
I use bit-wise assignments similar to this quite a lot. Are you saying that I need to be more careful as unexpected things can happen? I've picked out a particularly ugly piece of code that is part of my driver for an e-paper display which works.
Nothing unexpected should be happen.
@David. I am assuming you are on v.0.95.010
@Fábio Almeida ... I am thinking you are not on v.0.95.010. Let us know. As the code below works correctly (prints 32). Also, which chip?