B4J Code Snippet Be careful with IF number=number!

I work on a swaping xCustomListview and spent half an hour to find a bug. At the end I recognized that the bug was no logic error. The code was correct. But it was a casting prolem:
B4X:
Value as int=3
Panel.Tag=Value

'this throws FALSE:
If Panel.Tag=Value Then
    log(" once TRUE")
Else
    log(" FALSE ???")
End If

'this throws TRUE:
If Value = Panel.Tag Then
    log("again TRUE")
End If

be careful to think about what you position first in a IF statement. This effects the casting!!!
 
Last edited:

TILogistic

Expert
Licensed User
Longtime User
Maybe you're having this issue.

New warning:
"Comparison of Object to other types will fail if exact types do not match.
Better to put the object on the right side of the comparison. (warning #35)"
See this post for more information: https://www.b4x.com/android/forum/t...-is-available-for-download.117877/post-737515.

sorry;

 

Midimaster

Active Member
Licensed User
yes i know and i already knowed it. But often I don't care.. So it happens.

I wanted to place the warning, that other (new users) hear about it.
 
Last edited:

kimstudio

Active Member
Licensed User
Longtime User
Thanks for the warning. Good to know. I first thought it is a "=" to "==" problem then I realized in B4X logic equals is "=" instead of "==". I checked my code and found there are many "==" there and strange it seems they also work.
 
Top