GPS converter

Discussion in 'Questions (Windows Mobile)' started by wolfgang, Dec 1, 2008.

  1. wolfgang

    wolfgang Member Licensed User

    Hi,
    what is wrong with this code:
    Code:
    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.
     

    Attached Files:

  2. agraham

    agraham Expert Licensed User

    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.
    Code:
    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: Dec 1, 2008
  3. wolfgang

    wolfgang Member Licensed 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.
     
  4. agraham

    agraham Expert Licensed User

    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.
     

    Attached Files:

  5. wolfgang

    wolfgang Member Licensed User

    Hi,
    thanks again. In the meantime I found a solution (the same like yours).
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice