Thanks - here is my modified code.
This is a simple one button form that gets the lat/lon from the a/c and offers to open a chart web site.
I used your format string but it had some non-numeric'ness to the returned string. I resorted to the deprciated, but handy, Val() to clean it up. The code is verbose, I didn't want to string a bunch of operations together for the post.
Is there an elegant way to check to see if Open() was called and we're still connected?
What's the check that the a/c is "ready?" (loaded by FSX/P3D and ready to respond)
In the code sample I Open() once then error out on other calls. I close the conenction when the form closes. Bad technique? If the form made other calls to other offsets would things get balled up? GetLatLongString() below should probably have some busy logic to avoid a second call from wherever.
I couldn't find a good list of offsets - is FSUIPC4 Offsets Status.pdf the best available?
Option Explicit On
Imports FSUIPC
' Project Reference to FSUIPCClient.dll
Public Class frmACLocation
Private Sub btnGetLatLong_Click(sender As Object, e As EventArgs) Handles btnGetLatLong.Click
Try
Dim sLatLon As String = GetLatLongString()
If sLatLon <> "error" Then
If MsgBox("a/c Lat/Lon: " & sLatLon & vbCrLf & "Open Chart?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
Process.Start("http:\\skyvector.com/?ll=" & sLatLon & "&zoom=3")
End If
End If
Catch ex As Exception
MsgBox(ex.Message, , "btnGetLatLong_Click")
End Try
End Sub
Function GetLatLongString() As String
Dim ofsLatitude As Offset(Of Long) = New Offset(Of Long)(&H560)
Dim ofsLongitude As Offset(Of Long) = New Offset(Of Long)(&H568)
Dim mlat As FsLatitude
Dim mlon As FsLongitude
Dim sLat As String = ""
Dim sLon As String = ""
Try
Try
' is there a better test to see if Open() has happened and we're connected
FSUIPCConnection.Open()
Catch ex As Exception
' assume already Open
' next call with throw an error if that was not the case
End Try
FSUIPCConnection.Process()
mlat = New FsLatitude(ofsLatitude.Value)
mlon = New FsLongitude(ofsLongitude.Value)
sLat = mlat.ToString(False, "d", 6)
sLon = mlon.ToString(False, "d", 6)
sLat = Val(sLat) ' strip off leading zeros and * symbol
sLon = Val(sLon)
Return sLat & "," & sLon
Catch ex As Exception
' Badness occurred - show the error message
MsgBox(ex.Message, , "GetLatLongString")
Return "error"
End Try
End Function
Private Sub frmACLocation_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try
FSUIPCConnection.Close()
Catch ex As Exception
End Try
End Sub
End Class