Jump to content
The simFlight Network Forums

Visual Basic 6, reading Lat and Long


Recommended Posts

OK, So im create an ACARS style program and have got it working to extract everything i need so far, only problem im having is with the latitude and longitude and was wondering if someone could point me in the right direction!

Ive adapted the code from http://www.mycockpit.org/forums/showthr#post87129

And got this

Dim dwResult As Long
Dim latHi As Double
Dim latLo As Double
Dim latitude As Double

Dim longHi As Double
Dim longLo As Double
Dim longitude As Double

latHi = "0"
latLo = "0"
latitude = "0"

longHi = "0"
longLo = "0"
longitude = "0"

  If FSUIPC_Read(&H564, 4, VarPtr(latHi), dwResult) And FSUIPC_Read(&H560, 4, VarPtr(latLo), dwResult) Then
     ' "Read" proceeded without any problems
    If FSUIPC_Process(dwResult) Then
      ' "Process" proceeded without any problems

If latLo = "0" Then
    latLo = latLo / (65536# * 65536#)
End If

If latHi > 0 Then

latitude = latHi + latLo

Else

latitude = latHi - latLo

End If

    Lati.Caption = latitude

      End If
      End If

Any ideas or if I can extract it using a 64 bit integer using VB6? Ive tried a double but got nothing out of it, have been using FS Interrorgate to read the values and try and match up what it says with what I get!

Any help would be much appreciated!

Link to comment
Share on other sites

OK, So im create an ACARS style program and have got it working to extract everything i need so far, only problem im having is with the latitude and longitude and was wondering if someone could point me in the right direction!

I'm afraid I don't know VB enough to give you any solutions -- I'm sure others can do that -- but the big error I can spot is that your are reading 32 bit (4-byte) fixed point numbers into 64-bit (8 byte) variables (Doubles), and then treating the results as a 64 bit Doubles. If you must read them in two parts because you can't find a 64-bit integer variable type, you must at least read them into the right type of variable and treat them for what they are. Floating point formatted numbers are very different.

BTW, do statements like

latHi = "0"

really work, and give no compilation error? You declared "latHi" as a Double yet you appear to be assigning a string to it!

Regards

Pete

Link to comment
Share on other sites

So should I be able to read the full variable into a double instead of getting 2 parts?

No, not a Double. Although a Double is 64 bits it is a floating point number, and the latitude and longitudes are not, they are fixed point numbers. Totally different format, as I think I mentioned.

Pete

Link to comment
Share on other sites

The code at the top of the following thread shows how to read the lon and lat in VB6. It uses a currency type which is actually a 64bit integer type in VB6.

http://forums.simflight.com/viewtopic.php?f=54&t=72968&start=0&st=0&sk=t&sd=a

Paul

Got it working, thanks to the link!

Thanks a lot!!

BTW, do statements like

latHi = "0"

really work, and give no compilation error? You declared "latHi" as a Double yet you appear to be assigning a string to it!

Regards

Pete

Dont know Pete, I was just trying to convert the code I had found into visual basic code, and failing miserably!!

Link to comment
Share on other sites

BTW, do statements like

latHi = "0"

really work, and give no compilation error? You declared "latHi" as a Double yet you appear to be assigning a string to it!

Yeah they do work. VB is not a strongly-typed language so no type checking is performed by a vb compiler. You don't even need to declare variables. If there is a type-mismatch in the code, as in the above example, the vb runtime attempts a conversion. If it can't do it it'll give a runtime error. If it can convert then everything continues normally and the programmer is none-the-wiser.

If a variable is used without having been declared it gets declared on-the-fly by the vb runtime as a 'Variant' type.

It certainly makes it easy for beginners to get a program working without learning about types and casts; but I rather tend to view that it does more harm than good in the long run.

Paul

Link to comment
Share on other sites

Yeah they do work. VB is not a strongly-typed language so no type checking is performed by a vb compiler. You don't even need to declare variables. If there is a type-mismatch in the code, as in the above example, the vb runtime attempts a conversion. If it can't do it it'll give a runtime error. If it can convert then everything continues normally and the programmer is none-the-wiser.

If a variable is used without having been declared it gets declared on-the-fly by the vb runtime as a 'Variant' type.

I see. The Lua language I'm supporting for plug-ins is like that only more so. No declared types at all. But even I came unstuck in one piece of advice. I was thinking "C" style and told someone to do

if ipc.testbutton(joy, btn) == 0 then ...

completely forgetting that this function of mine returns a BOOLEAN which can only be true or false, not 0. If fact the only thing that's ever 0 is the number 0! Everything else is effectively non-zero in the sense that it isn't equal to it. There's even a nil value, which is simply the "value" something has when it doesn't have a value! That's not 0 either. ;-)

Flexible? Yes, very. Confusing too at times though, you're right! ;-)

Pete

Link to comment
Share on other sites

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.