Jump to content
The simFlight Network Forums

VB6 help with data types and offsets


Recommended Posts

I am playing around within VB6 to familiarise myself with the offsets and how they work etc

Code I have written is as follows :

Dim dwResult As Long

Dim VS As Long 'vertical speed

Dim Strobe As Byte 'strobes on/off 1=on 0=off

Dim altitude As Long 'altitude

If FSUIPC_Read(&H2C8, 4, VarPtr(VS), dwResult) Then

If FSUIPC_Read(&H281, 1, VarPtr(Strobe), dwResult) Then

If FSUIPC_Read(&H570, 8, VarPtr(altitude), dwResult) Then

'offset address,size(read value from FSInterrogate),variable to store result

'"Read" proceeded without any problems

If FSUIPC_Process(dwResult) Then

' "Process" proceeded without any problems

lbltest.Caption = "Vertical speed = " & Int(VS * 60 * 3.28084 / 256)

lblstrobe.Caption = "Strobe = " & Strobe

lblaltitude.Caption = "altitude = " & altitude * 3.28084 / (65536 * 65536)

Else

' Unable to "Process"

lbltest.Caption = "Processing: " & ResultText(dwResult)

End If

Else

' Unable to "Read"

lbltest.Caption = "Reading: " & ResultText(dwResult)

End If

End If

End If

What would be the correct data type to load an 8bit signed, 64bit fixed etc. I get a correct VS reading but the altitude when flying at 5000ft reads something like -0.0322330.

Are there any VB6 samples other than what came with the SDK?

Many thanks

Graham

Link to comment
Share on other sites

Dim altitude As Long 'altitude

...

If FSUIPC_Read(&H570, 8, VarPtr(altitude), dwResult) Then

...

lblaltitude.Caption = "altitude = " & altitude * 3.28084 / (65536 * 65536)

...

What would be the correct data type to load an 8bit signed, 64bit fixed etc. I get a correct VS reading but the altitude when flying at 5000ft reads something like -0.0322330.

I don't really know VB data types, but I think you have an error there somewhere. You define dwResult and vertical speed as "Long", so I assume "Long" refers to a 32 bit value? If that is so, then you are reading 8 bytes into the altitude "long" which is probably 4 bytes only (i.e. 32 bit). Even if the extra 4 bytes only destroys something unimportant, and therefore doesn't crash your program, your variable "altitude" will only contain the fractional part -- which, incidentally, is unsigned not signed as you are computing it as.

There are two alternatives, at least. If an accuracy of 1 metre is sufficient for your needs, then simply keep your code the same excpt read offset 0574, and don't divide by 65536 * 65536.

Otherwise you need to find if VB6 supports 64-bit fixed point numbers. If so, read into one such.

In C/C++ Microsoft added the type __int64 for this. There is also an extension to the C/C++ definition to allow "long long" to mean the same.

Check your VB manuals.

I have a brief VB.NET reference here, and that shows "Integer" as 32 bit, "Long" as 64 bit and "Short" as 16 bit. If that was true in VB6 then your code should more or less work, excepting that you should either redefine Vertical speed and dwResult as "Integer", or zero them beforehand to make sure there's no rubbish left in the unwritten high 32 bits.

Maybe VB6 has no 64-bit integers, in which case you have more work to do. You will have to read the altitude in two parts -- the fraction from 0570 and the units (metres) from 574, both into Integers. You can convert both, separately, then add them -- the integer part only needs multiplying by 3.28084 to get feet. The fractional part similarly, then dividing by the 65536 * 65536 value. However, there's a problem -- the fraction isn't signed, all 32-bits are significant, and it has the same sign as the integral part (obviously, as it was really only one 64 bits number, with one sign bit at the top).

I don't think VB supports unsigned integers (very bad omission), so you'd need to figure out some arithmetic manipulations to get the fraction correct. Probably something like checking if it is negative, then, if so, negate it, do the calculation, then subtract it from 1 metre (3.28084 feet by now).

Once you have a (positive) fraction properly computed, you need to add it to a positive integral part, or subtract it from a negative integral part.

Don't be frightened by any of this. It is really all simply logic and arithmetic.

Regards,

Pete

Link to comment
Share on other sites

wow, thanks for the detailed reply Pete.

I will try and digest what you suggest tomorrow as it is 1am now and I am up at 6 for work.

Out of interest I have found that within VB6 defining a long gives a range of -2,147,483,647 to 2,147,483,647, a Double is a 64bit number - fixed or floating.

Now using FS-Interrogate and looking at offset 0578 Pitch the raw number read in the 32bit section is 4,291,248,153. Now this will not fit into the 'long' type as I get an overflow error. It also wont fit into the 'double' type as I get a type mismatch.

So if anyone works with VB6 does that suggest that there are no types that can read a number that big?

I will play around further tomorrow night

Thanks again

Graham

Link to comment
Share on other sites

Out of interest I have found that within VB6 defining a long gives a range of -2,147,483,647 to 2,147,483,647, a Double is a 64bit number - fixed or floating.

Your "Long" is 32-bit only then, same as your Integer. "Double" will be floating point, not fixed, it is one of thetwo standard types of floating point representations supported by the hardware. The other is 32-bit, known as "float" in C (maybe "Single" in VB6?).

It also wont fit into the 'double' type as I get a type mismatch.

Yes, floating point is an entirely different format. Please look at this, which I just found by Google:

http://dev.mysql.com/tech-resources/articles/visual-basic-datatypes.html

Looks like you will either have to make do with 1 metre accuracy or do the stuff in two parts as I suggested. Or, of course, you could upgrade to VB.Net? ;-) Look at this (about VB.Net):

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vadatLong.asp

Regards,

Pete

Link to comment
Share on other sites

for plane altitude, i use the following

Dim x As Long

Dim dwResult As Long

Call FSUIPC_Read(&H574, 4, VarPtr(x), dwResult) 'meters

Call FSUIPC_Process(dwResult)

Plane_Alt = Mtof(CSng(x))

Link to comment
Share on other sites

for plane altitude, i use the following

Dim x As Long

Dim dwResult As Long

Call FSUIPC_Read(&H574, 4, VarPtr(x), dwResult) 'meters

Call FSUIPC_Process(dwResult)

Plane_Alt = Mtof(CSng(x))

Yes, this is good enough if accuracy to 1 metre is sufficient. ;-)

Regards,

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.