A a n g l o Active Member Licensed User Longtime User Jul 16, 2022 #1 the following code : B4X: Copy Dim a As Int a=2 If a =1 Then Log(1) Else If a=2 Then Log(2) End If does not raise any red issues / warning issues from the IDE (b4J). but it does NOT log "2" (as expected ??). only if the 'log(2)' moved to next line - it logs it ok. so, if writing this way is a syntax mistake/error - the IDE should warn you about that. and if not, it should work (as expected ??). BTW - just tried it on vb6 ide - it's accepted and works there. (not that it binds b4x in any way). if i'm missing something, please let me know. thank you.
the following code : B4X: Copy Dim a As Int a=2 If a =1 Then Log(1) Else If a=2 Then Log(2) End If does not raise any red issues / warning issues from the IDE (b4J). but it does NOT log "2" (as expected ??). only if the 'log(2)' moved to next line - it logs it ok. so, if writing this way is a syntax mistake/error - the IDE should warn you about that. and if not, it should work (as expected ??). BTW - just tried it on vb6 ide - it's accepted and works there. (not that it binds b4x in any way). if i'm missing something, please let me know. thank you.
jahswant Well-Known Member Licensed User Longtime User Jul 16, 2022 #2 Yes that’s a parser failure. You have to move to the next line to the right execte. Upvote 0
agraham Expert Licensed User Longtime User Jul 16, 2022 #3 No it's not a parser failure. Single line If ... Then ... has always been allowed in B4X. Check the Intellisense for If Single line: If condition Then true-statement [Else false-statement] Multiline: If condition Then statement Else If condition Then statement ... Else statement End If Click to expand... Though if does seem to not work as expected after an Else. So while not necessarily a parser failure it does look like a bug of some sort! Upvote 0
No it's not a parser failure. Single line If ... Then ... has always been allowed in B4X. Check the Intellisense for If Single line: If condition Then true-statement [Else false-statement] Multiline: If condition Then statement Else If condition Then statement ... Else statement End If Click to expand... Though if does seem to not work as expected after an Else. So while not necessarily a parser failure it does look like a bug of some sort!
P PaulMeuris Well-Known Member Licensed User Jul 16, 2022 #4 You could also write it like this: Code: Copy Dim a As Int a=2 If a =1 Then Log(1) Else If a=2 Then Log(2) End If This way the single line if is on one line and nothing preceeds it. Upvote 0
You could also write it like this: Code: Copy Dim a As Int a=2 If a =1 Then Log(1) Else If a=2 Then Log(2) End If This way the single line if is on one line and nothing preceeds it.
jahswant Well-Known Member Licensed User Longtime User Jul 16, 2022 #5 But the parser should understand that it doesn’t apply to this case ! Upvote 0
agraham Expert Licensed User Longtime User Jul 16, 2022 #6 jahswant said: But the parser should understand that it doesn’t apply to this case ! Click to expand... Why shouldn't it apply in this case? Other than Erel decided not to support it in which case it should produce a warning. Only Erel can tell us what the original intent was.? Upvote 0
jahswant said: But the parser should understand that it doesn’t apply to this case ! Click to expand... Why shouldn't it apply in this case? Other than Erel decided not to support it in which case it should produce a warning. Only Erel can tell us what the original intent was.?
MegatenFreak Active Member Licensed User Jul 17, 2022 #7 There are two ways to put that example into one line: Code: Copy 'Solution 1: using colon to indicate a new line: If a =1 Then : Log(1) : Else If a=2 Then : Log(2) : End If 'Solution 2: using a ternary structure: Log (IIf(a=1, 1, IIf(a=2, 2, ""))) Upvote 0
There are two ways to put that example into one line: Code: Copy 'Solution 1: using colon to indicate a new line: If a =1 Then : Log(1) : Else If a=2 Then : Log(2) : End If 'Solution 2: using a ternary structure: Log (IIf(a=1, 1, IIf(a=2, 2, "")))
Erel B4X founder Staff member Licensed User Longtime User Jul 17, 2022 #8 It is considered invalid syntax. I will check why there is no parser error... Upvote 0
LucaMs Expert Licensed User Longtime User Jul 17, 2022 #10 Maybe I'm not awake yet ? but in my opinion the code in the first post is fine as well, without reporting errors. B4X: Copy If a =1 Then Log(1) Else If a=2 Then Log(2) End If Last edited: Jul 17, 2022 Upvote 0
Maybe I'm not awake yet ? but in my opinion the code in the first post is fine as well, without reporting errors. B4X: Copy If a =1 Then Log(1) Else If a=2 Then Log(2) End If
jahswant Well-Known Member Licensed User Longtime User Jul 17, 2022 #11 Erel said: It is considered invalid syntax. I will check why there is no parser error... Click to expand... I told you it’s a parser failure. There’s are other cases like this one. I don’t remember but I will post if I encounter them. Upvote 0
Erel said: It is considered invalid syntax. I will check why there is no parser error... Click to expand... I told you it’s a parser failure. There’s are other cases like this one. I don’t remember but I will post if I encounter them.
A a n g l o Active Member Licensed User Longtime User Jul 17, 2022 #12 Erel said: View attachment 131495 Click to expand... Erel thank you, as for the image you uploaded : no such red error marks here (b4j 9.8). i belive i'm not the only one here that can say that. i'd like to know what to do to have that error marks as well. it may seems a little issue but belive me, it's not : it is a project where there are more then 1700 'Else If'. on friday i've found 1 case where the following 'Then' expresion is in the same line. AS THERE IS NO ERROR from the IDE about that, AND the 'Then' part is ignored (treated as comment....) ==> ==> the algorithem produce a wrong calulation/result. now, if i found 1, there maybe more. i'd like the IDE to point me to them, otherwise, i'll have to write code to find syntax errors.... Thank you Upvote 0
Erel said: View attachment 131495 Click to expand... Erel thank you, as for the image you uploaded : no such red error marks here (b4j 9.8). i belive i'm not the only one here that can say that. i'd like to know what to do to have that error marks as well. it may seems a little issue but belive me, it's not : it is a project where there are more then 1700 'Else If'. on friday i've found 1 case where the following 'Then' expresion is in the same line. AS THERE IS NO ERROR from the IDE about that, AND the 'Then' part is ignored (treated as comment....) ==> ==> the algorithem produce a wrong calulation/result. now, if i found 1, there maybe more. i'd like the IDE to point me to them, otherwise, i'll have to write code to find syntax errors.... Thank you
Erel B4X founder Staff member Licensed User Longtime User Jul 17, 2022 #13 a n g l o said: no such red error marks here (b4j 9.8). Click to expand... True. It will show in the next version. Upvote 0
a n g l o said: no such red error marks here (b4j 9.8). Click to expand... True. It will show in the next version.
MicroDrie Well-Known Member Licensed User Longtime User Jul 17, 2022 #14 a n g l o said: it is a project where there are more then 1700 'Else If'. Click to expand... The very large number of IF / ELSE statements reminds me of the time when we had to "normalize" such a function in school, so that the duplications were removed and a simplification occurred. You often see that a specific condition often excludes several possible. This greatly reduces the number of tests. Upvote 0
a n g l o said: it is a project where there are more then 1700 'Else If'. Click to expand... The very large number of IF / ELSE statements reminds me of the time when we had to "normalize" such a function in school, so that the duplications were removed and a simplification occurred. You often see that a specific condition often excludes several possible. This greatly reduces the number of tests.