Bug? Bugs in B4A V 10

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Hello all,

Yesterday I upgraded the version of my B4A from 9.80 to 10.0. Just after the upgrade I noticed that some maps aren't showed anymore in a debug break point when I put the mouse cursor over the variable (which is bad because causes some difficulty to debug ).
But today I noticed a very bad error: in a app that was working fine some lists elements were duplicated. Debugging I discovered that a comparison test to check if the respective line is multiple of 20 (when and alert line should be showed) isn't working anymore.
In this test I get the line number and store it in an int variable, comparing with the original value. Something like this:

B4X:
    Dim intLine as int
    Dim lineMod as as double
    for i = 0 to maxLines
        intLine = i/20
        lineMod  = i /20
        if lineMod = intLine then
           ... <- here the code to show the line each 20 lines
        end if
    next

The code above, in B4A v.10, is returning true in the test even when intLine is 0 and lineMod is 0.05 (which is wrong and in different from the behavior of the previous versions). This looks like a bug (together with the problems of maps showing in debug mode).
Please, does anybody is having the same problems?

Thanks!

1594913230120.png
 
Last edited:

Pendrush

Well-Known Member
Licensed User
Longtime User
You compare integer and double are they equal?
B4X:
Dim a As Int = 1
Dim b As Double = 1.9
If a = b Then
   Log("equal")
Else
   Log ("not equal")
End If
this will print in log "equal".
If you want this to work as expected, you need to compare same type, int with int or double with double.
 
Last edited:

Marcos Alves

Well-Known Member
Licensed User
Longtime User
You compare integer and double are they equal?
B4X:
Dim a As Int = 1
Dim b As Double = 1.9
If a = b Then
   Log("equal")
Else
   Log ("not equal")
End If
this will print in log EQUAL
Yes ! This is clearly wrong no ?
 

Star-Dust

Expert
Licensed User
Yes ! This is clearly wrong no ?
try this
B4X:
Dim a As Int = 1
Dim b As Double = 1.9
If b = a Then
   Log("equal")
Else
   Log ("not equal")
End If

this will print in log NOT EQUAL
 

Pendrush

Well-Known Member
Licensed User
Longtime User
try this
B4X:
Dim a As Int = 1
Dim b As Double = 1.9
If b = a Then
   Log("equal")
Else
   Log ("not equal")
End If

this will print in log NOT EQUAL
Test the code please

EDIT: oh.. I did not see that you have replaced side :)
 

Star-Dust

Expert
Licensed User
See this

 

Star-Dust

Expert
Licensed User
B4A 9.90 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.




This happen that with the new versions, the first variable in comparison is the one that determines the type of comparison.

If the former is int the latter will be casteded int
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
No... I always use this kind of comparison to know if a number is divisible by other.
1. Create an int as variable (r1)
2. Create a double. (r2)

put the same division result in both... (example: a/b). If r1 is equal to r2, then a is divisible by b. Else, it isn't . (r1 = a/b has the same effect of legacy code in Visual Studio MS platform - Legacy Visual Basic... - r2 = int(a/b) )
And the most important: this WAS working in the previous B4A version (I checked - I was using 9.30 and upgraded to 10 yesterday)
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
B4A 9.90 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.




This happen that with the new versions, the first variable in comparison is the one that determines the type of comparison.

If the former is int the latter will be casteded int
Which means that I need to swap the order of the variables in the comparison right?
 

Star-Dust

Expert
Licensed User
No... I always use this kind of comparison to know if a number is divisible by other.
1. Create an int as variable (r1)
2. Create a double. (r2)

put the same division result in both... (example: a/b). If r1 is equal to r2, then a is divisible by b. Else, it isn't . (r1 = a/b has the same effect of legacy code in Visual Studio MS platform - Legacy Visual Basic... - r2 = int(a/b) )
And the most important: this WAS working in the previous B4A version (I checked - I was using 9.30 and upgraded to 10 yesterday)
Sorry I did not understand, fas an example of what you mean
 

Star-Dust

Expert
Licensed User
Which means that I need to swap the order of the variables in the comparison right?
With the code you posted, it really means swapping places
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
With the code you posted, it really means swapping places
Ok, I only swapped the order of the factors in if and worked. I know many languages and in my 30 years of programming I never saw this behavior. For me it's a bug.
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
Sorry I did not understand, fas an example of what you mean
Objective: discover if a number is divisible by other:

Approach 1: use the "int" command (which doesn't exist in B4A): ex: if (a/b) = int(a/b) then log('OK')

Approach 2: store the result in a int variable and compare:
Dim r as int = (a/b)
if r = (a/b) then log('OK')

that's what I mean. 👍 ;)
 
Last edited:

Alex_197

Well-Known Member
Licensed User
Longtime User
Objective: discover if a number is divisible by other:

Approach 1: use the "int" command (which doesn't exists in B4A): ex: if (a/b) = int(a/b) then log('OK')

Approach 2: store the result in a int variable and compare:
Dim r as int = (a/b)
if r = (a/b) then log('OK')

that's what I mean. 👍 ;)
Why not use mod?

Mod:
If aDouble mod bInt = 0 then
else
end if
 

Pendrush

Well-Known Member
Licensed User
Longtime User
As you can see, this is not posible in Android Studio you can also see error explanation.
Erel make it to work in B4x, but comparing different type is not posible in any other language that I know.

as-test.png
 

Marcos Alves

Well-Known Member
Licensed User
Longtime User
As you can see, this is not posible in Android Studio you can also see error explanation.
Erel make it to work in B4x, but comparing different type is not posible in any other language that I know.

View attachment 97236
In php you can compare different types. In legacy VB from MS Visual Studio (in which it's supposed to be based B4A either). In Pascal and Fortran its possible also. In the "died" C Builder from Borland it's possible also.
 
Top