Problem with switch
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Problem with switch
I have some code to check the contents
of variables tVar1[Line01] to tVar1[Line11].
The contents of the elements of tVar1 are
either 1 or 0. There can be one or two cases
where the variable is 1.
The switch code is
case tVar[Line01] > 0
do the biz
...
case tVar[Line11] > 0
do the biz
Problem is that if Line07 is 1 the code is run OK
but then all the following case statements
code is run even though the variable value is 0.
So in a case where Line6 and Line7 are set to
1 the result I get is 6 and 11 instead of 6 and 7.
Seems that after finding one case where
the variable is 1 it ignores the "case" condition
for all the remaining case statements.
Can't use "break" after the first "1" value is
found since the second case won't be checked.
Any ideas?
of variables tVar1[Line01] to tVar1[Line11].
The contents of the elements of tVar1 are
either 1 or 0. There can be one or two cases
where the variable is 1.
The switch code is
case tVar[Line01] > 0
do the biz
...
case tVar[Line11] > 0
do the biz
Problem is that if Line07 is 1 the code is run OK
but then all the following case statements
code is run even though the variable value is 0.
So in a case where Line6 and Line7 are set to
1 the result I get is 6 and 11 instead of 6 and 7.
Seems that after finding one case where
the variable is 1 it ignores the "case" condition
for all the remaining case statements.
Can't use "break" after the first "1" value is
found since the second case won't be checked.
Any ideas?
Life is just a bowl of cherries.
Hi bjb007
Sandwiching the above between lock screen and unlock screen might help as well...
Hope I've given you good advice there!

If you stick to if...then statements in this instance, you shouldn't have any probs, I reckon, i.e:Seems that after finding one case where
the variable is 1 it ignores the "case" condition
for all the remaining case statements.
Code: Select all
if tVar[Line01] = 1 then
--do the biz
end if
if tVar[Line02] = 1 then
--do the biz
end if
Hope I've given you good advice there!

Problem with switch
gyro
Got bored with if...end if statements and
decided to have a change!
Guess that "switch" is only intended for
picking one option from a number
of choices. Hence the "break" word.
Wonder are their any other ways of making
multiple choices than if..end if.
Got bored with if...end if statements and
decided to have a change!
Guess that "switch" is only intended for
picking one option from a number
of choices. Hence the "break" word.
Wonder are their any other ways of making
multiple choices than if..end if.
Life is just a bowl of cherries.
That's useful info from Malte, I've learned something there! (I've tended to steer clear of case stuff, in preference to if...then, don't know why...)
Just thought I'd add (but I'm sure you know anyway) that when you do use multiple if...then statements, they can be simplified if put on one line, so without any need for the "end if":

Just thought I'd add (but I'm sure you know anyway) that when you do use multiple if...then statements, they can be simplified if put on one line, so without any need for the "end if":
Code: Select all
if tVar[Line01] = 1 then --do the biz--
if tVar[Line02] = 1 then --do the biz --

Maybe a tad bit early to post.
However, there is a small article on switch coming up in the developers section of my site. Click here to view it.
However, there is a small article on switch coming up in the developers section of my site. Click here to view it.