Bug? For each Type in List bug?

nibbo

Active Member
Licensed User
Longtime User
I have a declared type i.e:
B4X:
Type Vehicle (RegistrationNumber As String, Model As String)

I populate a list of these and the try a for each:

B4X:
For Each V as Vehicle In VehicleList
  if V.RegistrationNumber = "XXX" then
            ....
  End If
Next

However this does not find the vehicle with registration XXX...?
Instead I seem to have to force V into existence by using
B4X:
Dim X as string = V.RegistrationNumber
before the If statement and then it is found OK.
NB this behaviour only happens in release mode, in debug it finds XXX just fine!
 

nibbo

Active Member
Licensed User
Longtime User
What is the EXACT code here?
B4X:
 if V.RegistrationNumber = "XXX" then

The EXACT code is...
B4X:
Sub CheckVehicle(code As String) As Boolean
    ' try to match the input code to a registration number
    If VehicleList.IsInitialized Then
        For Each V As Vehicle In VehicleList
              ' see if we have a match
              If V.RegistrationNumber.ToUpperCase = code.ToUpperCase Then
                   ' match found
                     Return True
               End If
        Next
End If

' no match found so fail the method
Return False

End Sub

The above code works perfectly in debug mode but fails in release mode.
The value passed to the code parameter definitely exists in the list of Vehicles.
Adding the Dim X as string = V.RegistrationNumber within the loop above the If statement seems to make it work OK as if to force V into existence!

Thanks
 

nibbo

Active Member
Licensed User
Longtime User
Please post the code that fills VehicleList.

Hi Erel, Not sure what was happening but I have re-sequenced the way the activity loads and it is OK now.
Originally the app send an HTTP request and then attempted to connect to a Bluetooth barcode reader in the Activity Create.
If the barcode reader failed to connect it popped up an error message using BetterDialogs but then the HTTP request never returned to 'Sub JobDone' for some reason.
It was in Sub JobDone that the VehicleList was being populated which was not happening in the release version.
I think it was just a co-incidence that in debug mode things took a little longer to process causing the code to execute slightly differently.
I cannot imagine why the Bluetooth connection fail would cause the HTTP request to never come back!
I now connect to the barcode reader before firing off the HTTP request and everything seems to run OK.
Don't waste any of your valuable time on this as it would be almost impossible to recreate.
Thanks anyway.
 

DonManfred

Expert
Licensed User
Longtime User
Top