ButtonA(i).Toggle = (A_Array(i).Mode = TOGGLE_ON)
If A_Array(i).Mode = TOGGLE_ON Then
ButtonA(i).Toggle = True
Else
ButtonA(i).Toggle = False
End If
is this line:.... the same of this code ?
Is that a correct way ?
Better way to do it ?
(A_Array(i).Mode == TOGGLE_ON) ? ButtonA(i).Toggle = true : ButtonA(i).Toggle = false;
ButtonA(i).Toggle = (A_Array(i).Mode == TOGGLE_ON);
ButtonA(i).Toggle = A_Array(i).Mode = TOGGLE_ON
This is another possible way:
B4X:ButtonA(i).Toggle = IIF(A_Array(i).Mode = TOGGLE_ON, True, False)
IIF(condition, True, False)
condition
I have different opinion which I think I don't want to argue. My advice is to refractor the code to use appropriate data types.Sorry but I'm no so stupid boys?
I know you asked @aeric , so no problems.
TOGGLE_ON is not Boolean, it is a Global Byte (or Int, now I do not remember) variable, in this case TOGGLE_OFF is 0 and TOGGLE_ON is 1, but because I need to add more I do not just use a Boolean, I plained this when started a project. There are a couple of these.
Even A_Array(i).Mode that I compare to is Byte or Int, both the same type.
As it is a good pratice I always follow it and put costants in UPPER CASE.
but because I need to add more I do not just use a Boolean,
use appropriate data types.
If I know button toggle only has 2 possibilities then I would use Boolean data type.An integer numeric type seems entirely appropriate here.
Especially if B4X Select Case is likely to be used, or indexing into an array, or a state machine, or any bitfield templating.
if you use nested ternary then the code is hard to read..
I even set -1 on some to know that are unused, like a function that return -1.
Select Case is my favourite. Maybe because my habit of procrastinate a lot and I always leave many empty cases half way. ?Yes @emexes you are right, I cannot use Boolean, I need to use at least Byte, I've 3 and more options here and Boolean cannot handle, the right is Byte, I even set -1 on some to know that are unused, like a function that return -1.
I do large use of Select...Case...
var1 = (var2 = var3)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?