Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hello all.

As I dig around trying to make my small app work (it will, someday), I'll try to share some VB2008 code snippets so others can use, in case they need it.

The next subroutine will set the "arpt" global variable to the current airport's ICAO.

Recipe:

- You need a text file with all the airports, formatted like this:

(...)

EDDF;50.026422;8.543125

LPPT;38.781311;-9.135919

LPFR;37.014425;-7.965911

(...)

Maybe you can start with the one provided here (verify if the usage license allows you to use it in your app !)

Code:

You'll need:

Imports System.IO

In the form declarations (so it is globally available):

Dim arpt As String = ""

The subroutine itself (I didn't pay attention to the var types, so everyting is "double"feel free to correct my code !):

Sub mylocation(ByVal curlat As Double, ByVal curlon As Double)

Dim path As String = "path\to\your\textfile.txt"

Dim latdif As Double = 10000

Dim londif As Double = 10000

Dim sr As StreamReader = File.OpenText(path)

Do While sr.Peek()

Dim somatemp As Double = 0

Dim Alat As Double

Dim Blon As Double

Dim temp As String = sr.ReadLine()

Dim TestArray() As String = Split(temp, ";")

If TestArray(0) = "" Then Exit Do 'to avoid 'bogus' end-of-file...

Alat = Val(TestArray(1))

Blon = Val(TestArray(2))

If (Math.Abs(Alat - curlat) < latdif) And (Math.Abs(Blon - curlon) < londif) Then

latdif = Math.Abs(Alat - curlat)

londif = Math.Abs(Blon - curlon)

arpt = TestArray(0)

End If

Loop

sr.Close()

End Sub

Now, everytime you want to know in what airport your aircraft is, just call the subroutine like this:

mylocation(lat,lon)

using offsets 0x6010 for the latitude value and 0x6018 for the longitude one, and your "arpt" variable should reflect the current airport ICAO.

Feel free to correct my code (it's not pretty, but it's working for me ! ) and to share your own code snippets :-)

For instance, I'm looking for a "total payload weight calculator" subroutine for VB2008... ;-)

"V"

Posted

As I dig around trying to make my small app work (it will, someday), I'll try to share some VB2008 code snippets so others can use, in case they need it.

Thanks for your contributions.

Have you yet looked at the Lua program plug-in facilities in the latest interim updates for FSUIPC4 (see the FSX Downloads Announcement)? I know they are currently only for FSX, but I am really waiting for some feedback to see if it would be worth adding the same to FSUIPC3. So far it looks not, in fact. :-(

Little apps like idenfifying the nearest or current airport by ICAO seem very suitable for a Lua implementation, and the language isn't hard I think. FSUIPC4 runs any such plug-ins multithreaded in FSX's own process, with virtually no measurable impact on a 2- or 4-core system.

Best Regards

Pete

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.