GPS converter

wolfgang

Member
Licensed User
Longtime User
Hi,
what is wrong with this code:
B4X:
temp() = conv.WGS84UTMTOLatLon(32,temp(1),True,temp(0))
It works fine from the IDE but doesn't as an EXE. Attached the code an 2 samples.
 

Attachments

  • error.JPG
    error.JPG
    14.7 KB · Views: 170

agraham

Expert
Licensed User
Longtime User
Hi,
what is wrong with this code:
B4X:
temp() = conv.WGS84UTMTOLatLon(32,temp(1),True,temp(0))
Nothing as that is not where the problem lies! Lines like those below are causing the problem by confusing the optimising compiler, and because the line number where the error occurs is not reported by an optimised compiled app you think that when you comment out a line and the error disappears it is that line that is at fault. This is not necessarily so.
B4X:
Dim temp(0) 'As Double
 ....
temp() = StrSplit(data,",")
Initially you have declared temp() as Double and the optimising compiler has remembered this and will treat any references to elements of the array as Doubles. Later the optimising compiler has seen the allocation of StrSplit to temp() and notes that the array has now changed to a String array as that is what StrSplit returns. Any use of the elements of the temp() array it now treats as Strings. Unfortunately the order in which the optimising compiler notes the various whole array assignments to temp() is not necessarily same order in which they occur at runtime, so at runtime where the compiler compiled with an expectation of Strings or Doubles the array actually contains Doubles or Strings instead :( The solution is not to use strongly typed arrays for anything other than holding the return from a library (the most likely use). Use other untyped arrays for general purpose uses.

I have run into this problem several times now and I have had a couple of private email exchanges with Erel about it. I think that once an array is declared as typed it should not be allowed to change type. This would stop people like yourself running into these apparently inexplicable problems in the future.
 
Last edited:

wolfgang

Member
Licensed User
Longtime User
Hi,
thank you for your answer but I don't understand the solution. I used different types of variables but it’s always the same error.
 

agraham

Expert
Licensed User
Longtime User
Hi,
thank you for your answer but I don't understand the solution. I used different types of variables but it’s always the same error.
Look at the attached. The Double array LatLon() is used ONLY to receive the return from the library so it is always of type Double. The original temp() is no longer declared Double and is used for general purposes. The image button has no image as you didn't include it in the zip and it wouldn't run without it.
 

Attachments

  • ovl_kml_conv.sbp
    4.2 KB · Views: 186

wolfgang

Member
Licensed User
Longtime User
Hi,
thanks again. In the meantime I found a solution (the same like yours).
 
Top