Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi!

I'm trying to read the fuel in my aircaft, but i'm getting the error "Type missmatch". I cannot find anything wrong in the code, can anybody help? :?

Dim dwResult As Long
Dim fuel_l_lvl, fuel_l_cap, fuel_w As Long
Call FSUIPC_Read(&HB7C, 4, VarPtr(fuel_l_lvl), dwResult)
Call FSUIPC_Process(dwResult)
Call FSUIPC_Read(&HB80, 4, VarPtr(fuel_l_cap), dwResult)
Call FSUIPC_Process(dwResult)
Call FSUIPC_Read(&HAF4, 2, VarPtr(fuel_w), dwResult)
Call FSUIPC_Process(dwResult)
Dim fuel_left As Long
fuel_left = fuel_l_cap * ((fuel_l_lvl * 100 / (128 * 65536)) / 100) * (fuel_w / 256) * 0.4535924

' Fuel on board --> Center tank
Dim fuel_c_lvl, fuel_c_cap As Long
Call FSUIPC_Read(&HB74, 4, VarPtr(fuel_c_lvl), dwResult)
Call FSUIPC_Process(dwResult)
Call FSUIPC_Read(&HB78, 4, VarPtr(fuel_c_cap), dwResult)
Call FSUIPC_Process(dwResult)
Dim fuel_center As Long
fuel_center = fuel_c_cap * ((fuel_c_lvl * 100 / (128 * 65536)) / 100) * (fuel_w / 256) * 0.4535924

' Fuel on board --> Right tank
Dim fuel_r_lvl, fuel_r_cap As Long
Call FSUIPC_Read(&HB94, 4, VarPtr(fuel_r_lvl), dwResult)
Call FSUIPC_Process(dwResult)
Call FSUIPC_Read(&HB98, 4, VarPtr(fuel_r_cap), dwResult)
Call FSUIPC_Process(dwResult)
Dim fuel_right As Long
fuel_right = fuel_r_cap * ((fuel_r_lvl * 100 / (128 * 65536)) / 100) * (fuel_w / 256) * 0.4535924

Posted

I'm trying to read the fuel in my aircaft, but i'm getting the error "Type missmatch". I cannot find anything wrong in the code, can anybody help?

Sorry, I don't know about the mismatch (doesn't the compiler or debugger even tell you which line or variable has such a mismatch?), but your code is really enormously inefficient! Why are you calling FS for each little item of data separately? Please do all the FSUIPC_Reads, then one FSUIPC_Process at the end. The reads and writes cost nothing in PC terms, but every process call is swapping to Flight Sim, processing your requests, then swapping back to you. That's really dreadful! :-(

The whole point of separating the actual request to FS from all the individual items is to enable you to write efficient programs. Think of the Reads and Writes being your shopping list, with the Process call being the check-out.

Pete

Posted

I'm trying to read the fuel in my aircaft, but i'm getting the error "Type missmatch". I cannot find anything wrong in the code, can anybody help?

Sorry, I don't know about the mismatch (doesn't the compiler or debugger even tell you which line or variable has such a mismatch?), but your code is really enormously inefficient! Why are you calling FS for each little item of data separately? Please do all the FSUIPC_Reads, then one FSUIPC_Process at the end. The reads and writes cost nothing in PC terms, but every process call is swapping to Flight Sim, processing your requests, then swapping back to you. That's really dreadful! :-(

The whole point of separating the actual request to FS from all the individual items is to enable you to write efficient programs. Think of the Reads and Writes being your shopping list, with the Process call being the check-out.

Pete

I agree, the code is not best... :roll:

I have removed some Process calls now as you see bellow. :wink:

Do you meen like this?

Dim fuel_l_lvl, fuel_l_cap, fuel_w As Long
Call FSUIPC_Read(&HB7C, 4, VarPtr(fuel_l_lvl), dwResult)
Call FSUIPC_Read(&HB80, 4, VarPtr(fuel_l_cap), dwResult)
Call FSUIPC_Read(&HAF4, 2, VarPtr(fuel_w), dwResult)
Call FSUIPC_Process(dwResult)
Dim fuel_left As Long
fuel_left = fuel_l_cap * ((fuel_l_lvl * 100 / (128 * 65536)) / 100) * (fuel_w / 256) * 0.4535924

' Fuel on board --> Center tank
Dim fuel_c_lvl, fuel_c_cap As Long
Call FSUIPC_Read(&HB74, 4, VarPtr(fuel_c_lvl), dwResult)
Call FSUIPC_Read(&HB78, 4, VarPtr(fuel_c_cap), dwResult)
Call FSUIPC_Process(dwResult)
Dim fuel_center As Long
fuel_center = fuel_c_cap * ((fuel_c_lvl * 100 / (128 * 65536)) / 100) * (fuel_w / 256) * 0.4535924

' Fuel on board --> Right tank
Dim fuel_r_lvl, fuel_r_cap As Long
Call FSUIPC_Read(&HB94, 4, VarPtr(fuel_r_lvl), dwResult)
Call FSUIPC_Read(&HB98, 4, VarPtr(fuel_r_cap), dwResult)
Call FSUIPC_Process(dwResult)
Dim fuel_right As Long
fuel_right = fuel_r_cap * ((fuel_r_lvl * 100 / (128 * 65536)) / 100) * (fuel_w / 256) * 0.4535924

But i'm still getting the same error... :(

Posted

I have removed some Process calls now as you see bellow. :wink:

Do you meen like this?

No, I mean do one (1) process call for ALL the reads you want to do this cycle, not just arbitrarily bach them still with multiple calls to FS for no good reason. would you take separate trips to the supermarket to get three different things if you knew you wanted them all before you went the first time?

You only need to separate them if you need the results of one read to decide what else to read, or to decide upon something to write.

But i'm still getting the same error... :(

But that's a VB error, and the VB compiler or debugger will tell you precisely what is wrong, surely? That is why you use such a terrible language (my opinion, of course), isn't it? Because it is supposed to be easy? Surely it doesn't give obscure compile or runtime errors with no explanation?

Sorry, but I cannot help with VB. Try me on C. Maybe someone else will help, but if VB never tells you where it failed I don't see how you can use it in the first place. :-(

Regards,

Pete

Posted

I have removed some Process calls now as you see bellow. :wink:

Do you meen like this?

No, I mean do one (1) process call for ALL the reads you want to do this cycle, not just arbitrarily bach them still with multiple calls to FS for no good reason. would you take separate trips to the supermarket to get three different things if you knew you wanted them all before you went the first time?

You only need to separate them if you need the results of one read to decide what else to read, or to decide upon something to write.

But i'm still getting the same error... :(

But that's a VB error, and the VB compiler or debugger will tell you precisely what is wrong, surely? That is why you use such a terrible language (my opinion, of course), isn't it? Because it is supposed to be easy? Surely it doesn't give obscure compile or runtime errors with no explanation?

Sorry, but I cannot help with VB. Try me on C. Maybe someone else will help, but if VB never tells you where it failed I don't see how you can use it in the first place. :-(

Regards,

Pete

3 different shops ? :wink:

As the program key is in the .exe comment field, i can only test it outside VB, and then i complie it to an .exe i get no errors. :?

I'm planning to begin with a C language, but thats after this program is ready. :)

Posted

As the program key is in the .exe comment field, i can only test it outside VB, and then i complie it to an .exe i get no errors. :?

Hmmm, an FSUIPC registration would help there then. I didn't realise you hadn't even bought FSUIPC! :-(

Pete

Posted

As the program key is in the .exe comment field, i can only test it outside VB, and then i complie it to an .exe i get no errors. :?

Hmmm, an FSUIPC registration would help there then. I didn't realise you hadn't even bought FSUIPC! :-(

Pete

Nope, i only have the freeware key for the .exe recived from you.

But i will buy it, cuse when i started to work with FSUIPC i discovered

all the work included in it! Great work! :D

Now it would be great if someone could help me getting my program working? 8)

Posted
Now it would be great if someone could help me getting my program working? 8)

My initial guess is that the floating point ops you are doing barf when they attempt to get stored back into a Long. Try using a Double for your final result, and see what happens.

Cheers!

Luke

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.