Passing arrays in B4PPC6?

Discussion in 'Questions (Windows Mobile)' started by Frank, Jan 14, 2008.

  1. Frank

    Frank Member Licensed User

    Hi there,
    the backward compatibility issue list of B4PPC6 says "Arrays cannot be passed and returned from subs.".
    Thus my prgram fails when trying to do "optimized compilation".

    Is there any way to work around this?

    Below see the code that fails - actually taken from the demo app "GPS4PPC".
    When compiling the app, I receive an error "CS0266: Cannot implicitly convert type 'object' to 'string'..." on the line where it says "return res()".

    Is there anything I can do except of declaring these variables global?

    Thanks,
    Frank


    Sub Distance_Course (lat1,lon1,lat2,lon2)
    ErrorLabel(Distance_CourseErr)
    lat1 = lat1 * cPI / 180
    lon1 = -lon1 * cPI / 180
    lat2 = lat2 * cPI / 180
    lon2 = -lon2 * cPI / 180
    d = 2 * ASin(Sqrt((Sin((lat1-lat2)/2))^2 + Cos(lat1)*Cos(lat2)*(Sin((lon1-lon2)/2))^2))
    res.Distance = d * 180 * 60 /cPI
    If Cos(lat1) < 1e-7 Then
    If (lat1 > 0) Then
    tc1 = cpi
    Else
    tc1= 2*cpi
    End If
    Else
    sn = Sin(lon2-lon1)
    If Abs(sn) < 1e-7 Then
    If lat1 > lat2 Then tc1 = cpi Else tc1 = 2*cpi
    Else If sn < 0 Then
    tc1=ACos((Sin(lat2)-Sin(lat1)*Cos(d))/(Sin(d)*Cos(lat1)))
    Else
    tc1=2*cpi-ACos((Sin(lat2)-Sin(lat1)*Cos(d))/(Sin(d)*Cos(lat1)))
    End If
    End If
    res.Course = tc1 * 180 / cPI
    Return res()
    Distance_CourseErr:
    res.Distance = 0
    res.Course = 0
    Return res()
    End Sub
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You can download the updated source code.

    You to pass the arrays using global variables instead of the subs parameters.
    Instead of:
    Code:
    SomeArray() = Distance_Course(...)
    You should write:
    Code:
    Distance_Course(...)
    SomeArray() = res()
     
Loading...