Jump to content
The simFlight Network Forums

Need help from VB Gurus


Recommended Posts

I created application that has two command button and a label.... One command button is to increase value and other command button is to decrease value. Using FSUIPC write...so here's code snippet.

Private Sub Increase_Click()
Lfuelval 1
End Sub

Private Sub Decrease_Click()
Lfuelval -1
End Sub

Private Sub Lfuelval(ByVal argNum As Long)
Dim dwresult As Long
Dim setLfuelPct As Long
Dim Value

Call FSUIPC_Write(&HB7C, 4, VarPtr(setLfuel), dwresult)
Call FSUIPC_Process(dwresult)

setLfuelPct = Val(100) + argNum / 8372890 * (128 * 63556)
LFuelPct.Caption = Val(LFuelPct.Caption) + argNum
End Sub

It did not work, what did I do wrong?? if you can help I'd be appreicated.[/b]

Link to comment
Share on other sites

Private Sub Increase_Click()
Lfuelval 1
End Sub

Private Sub Decrease_Click()
Lfuelval -1
End Sub

Private Sub Lfuelval(ByVal argNum As Long)
Dim dwresult As Long
Dim setLfuelPct As Long
Dim Value

Call FSUIPC_Write(&HB7C, 4, VarPtr(setLfuel), dwresult)
Call FSUIPC_Process(dwresult)

setLfuelPct = Val(100) + argNum / 8372890 * (128 * 63556)
LFuelPct.Caption = Val(LFuelPct.Caption) + argNum
End Sub

I evidently don't understand VB at all. What is actually setting or changing value in the variable you are writing to 0B7C? What is "8372890"? Where are you reading and using the tank capacity, or are you assuming it is fixed (i.e. doing this for a specific aircraft)?

You seem to be updating something AFTER writing something else. It always worries me when I see arithmetic like

Val(100) + argNum / 8372890 * (128 * 63556)

What is done in what order? Do you know? I always use parentheses to force the order I know I want. In particular, if "argNum" is the +1 or -1 passed as a parameter, then dividing it by 8372890 will surely give zero!? After all, it is declared as a "long" so it isn't capable of storing fractional values is it?

Pete

Link to comment
Share on other sites

I evidently don't understand VB at all. What is actually setting or changing

value in the variable you are writing to 0B7C? What is "8372890"? Where are you reading and using the tank capacity, or are you assuming it is fixed (i.e. doing this for a specific aircraft)?

You seem to be updating something AFTER writing something else. It always worries me when I see arithmetic like

Val(100) + argNum / 8372890 * (128 * 63556)

What is done in what order? Do you know? I always use parentheses to force the order I know I want. In particular, if "argNum" is the +1 or -1 passed as a parameter, then dividing it by 8372890 will surely give zero!? After all, it is declared as a "long" so it isn't capable of storing fractional values is it?

Perhaps, I got really confused. Seem like I got myself in mess.. I have suceed getting my application to Read Fuel Capacity, Lbs, and Percentage. But Unable to clarify the logic in writing them. Actually it's my first time doing this

Say, if you were me... You use C ?? (I assume thats the programming language you are familar with) and you wanted to increase or decrease fuel % for center tank. How would you implement it? with calculation of Fuel Level and Capacity?

Let me know

Arthur

Link to comment
Share on other sites

Say, if you were me... You use C ?? (I assume thats the programming language you are familar with) and you wanted to increase or decrease fuel % for center tank. How would you implement it? with calculation of Fuel Level and Capacity?

Well, I've not done this in a program, but you could easily check for yourself using FSInterrogate (you can WRITE to FSUIPC in FSInterrogate as well as read and observe, you know).

Anyway, for just a simple percentage increase/decrease you don't need the actual capacities -- you'd only ever need capacities if you wanted a fixed number of gallons or litres or pounds of kilograms of change. You just need the fact that 100% level is known to be 128 * 65536, or 8388608.

In "pseudo-code" (i.e. no known language):

Read the levels for all tanks (in one Process call)

For each tank, assuming its level readout is now in 32-bit integer 'L'

For 1% increase:

  • L = L + 83886 (which is (128 * 65536) / 100, thus 1%)
    Check L <= 8388608 (this is 128 * 65536, representing 100%)
    -- if not set L = 8388608 (100%)

For 1% decrease:

  • L = L - 83886 (which is (128 * 65536) / 100, thus 1%)
    Check L >= 0
    -- if not set L = 0 (0%)

Write L back to level offset for this tank

Loop for next tank

Do the Process call for all the tanks written

Pete

Link to comment
Share on other sites

L = L + 83886 (which is (128 * 65536) / 100, thus 1%)

Check L <= 8388608 (this is 128 * 65536, representing 100%)

-- if not set L = 8388608 (100%)

For 1% decrease:

L = L - 83886 (which is (128 * 65536) / 100, thus 1%)

Check L >= 0

-- if not set L = 0 (0%)

Write L back to level offset for this tank

Loop for next tank

Do the Process call for all the tanks written

Interesting Theory Pete, I got this working now.... I created two VB button, one for increasing and other one for decreasing fuel, At that time, I simply click it at both ways and they either dump or increases fuel by 10 pounds on every button clicks.

Now I am working on VB "doevent" function (loop) and see if I could get it to lose few pound automatically following by clock ticks as if I engages fuel jettison. Your theory really helps.

Thanks

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.