Jump to content
The simFlight Network Forums

New FSUIPC programmer - help with VB


Recommended Posts

I'm new to programming with FSUIPC, and have started a little utility in VB. I'm working with the very helpful VB modules provided in the SDK but have a problem that hopefully is due to a simple error on my part.

I've set up a simple applicate to connect to FSUIPC and read the current Lat/Lon coordinates. I start FS (FS2002 or FS9 - same symptom), place the aircraft at the default field, and then run my app. The app connects to FSUIPC and reports the correct version number. It then tries to read the 8 bytes at location #0560 to get the latitude. In fact, I'm really just using the sample code in the VB readme file. Code is as follows:

Private Sub UpdatePosition()

'

Dim Fake64Bit1, Fake64Bit2 As Currency

Dim dwResult As Long

Dim Longitude, Latitude As Double

'

If Active Then

If FSUIPC_Read(&H560, 8, VarPtr(Fake64Bit1), dwResult) Then

' "Read" proceeded without any problems

If FSUIPC_Process(dwResult) Then

Latitude = Fake64Bit1 * 10000#

Latitude = Latitude * 90# / (10001750# * 65536# * 65536#)

lblLatitude.Caption = Str(Latitude)

Else

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

End If

Else

lblStatus.Caption = "Read: " & ResultText(dwResult)

End If

End If

End Sub

What happens is that Fake64Bit1 reports as 'empty'. This is odd, since I thought it had to at least take a value of zero. Can anybody tell me what I'm doing wrong?

Thanks for any assistance you can provide,

Philip.

Link to comment
Share on other sites

It would appear that the Currency data type is inappropriate for this. Try this instead. I'm sure this is not the most efficient method (I'm not that active in VB programming these days) but it works:

In General.bas declare this:

Public Type LLCoordinates
    dwLo As Long
    dwHi As Long
End Type


In main code block:

Private Sub Command2_Click()
Dim dwResult As Long
Dim FSLatitude As LLCoordinates
Dim ACLatitude As Double

  Call FSUIPC_Read(&H560, 8, VarPtr(FSLatitude), dwResult)
  Call FSUIPC_Process(dwResult)

  If FSLatitude.dwHi >= 0 Then
      ACLatitude = FSLatitude.dwHi + FSLatitude.dwLo / 68719476736#
  Else
      ACLatitude = FSLatitude.dwHi - FSLatitude.dwLo / 68719476736#
  End If
  ACLatitude = ACLatitude * 45# / 5000875#

  lblLatitude.Caption = Str(ACLatitude)
End Sub

I hope this helps.

Chris

Link to comment
Share on other sites

Chris,

Thanks for your help with this - the solution you've presented is much more elegant than what I was doing.

Unfortunately, my problem persists and I'm now starting to think it has something to do with the way VB is handling the FSUIPC calls themselves.

When I look in the Locals broswer after the process call, my variable has lost its data type - not even an LLCoordinates struct anymore. Bizarre.

Here's a link to a screenshot.

http://www.aavirtual.com/forums/attachment.php?s=&postid=19452

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.