Activating variable after running the subroutine

simurq

Board Regular
Joined
Nov 11, 2011
Messages
73
The main subroutine returns lots of stuff unrelated to aircraft (eg., weather forecast, distances and headings between waypoints, etc.). Inside of this subroutine I have a set of functions to calculate various aircraft parameters such as true airspeed, fuel consumption, etc. which use a few static variables called from GetParams() which returns an array of values depending on type of aircraft pre-selected by the user from a drop-down list before running the main subroutine. Eg.:

Code:
Public Function GPH(PP As Integer, plane As Integer) As Double
'* Calculates cruise fuel consumption (gallons per hour)
'* Input: (i) "PP" as engine brake-power percentage; (ii) "plane" as type of aircraft

    Dim AircraftData As Variant
    
    AircraftData = GetParams(plane)
    
    GPH = AircraftData(9) * PP ^ 2 + AircraftData(10) * PP + AircraftData(11)
    
End Function

Public Function GetParams(p_val As Integer) As Variant
'* Array contains static aircraft-specific data with the following parameters in order of declaration:
    '
    '   Type of aircraft
    '   Max TOW (lbs)
    '   Ceiling (ft)
    '   Wing area (sq ft)
    '   Rated engine power (hp)
    '   Climb fuel variables (for function CFUEL) - 4 items
    '   Cruise fuel variables (for function GPH) - 3 items
    '   CoeffClimb (CL) variables (for function KTAS) - 4 items
    '   CoeffClimb derivative (CL)' variables (for function KTAS) - 4 items
    '   Startup and taxi fuel
    
    Select Case p_val
        Case 1
            GetParams = Array("Cessna 172R Skyhawk", _
                            2450, _
                            12000, _
                            174, _
                            160, _
                            0.000000000003, -0.00000003, 0.00042, -0.0201, _
                            0.0002, 0.0901, 0.8544, _
                            0, 0.1257, -0.0333, 0.0454, _
                            0, 0.06285, 0.01665, -0.0681, _
                            1.1)
        Case 2
            GetParams = Array("Cessna 182T Skylane", _
                            3100, _
                            18000, _
                            174, _
                            230, _
                            0, 0.00000001, 0.0003, 0.1, _
                            0.0007, 0.0564, 4.796, _
                            -0.2215, 0.3476, -0.1113, 0.049, _
                            -0.33225, 0.1738, 0.05565, -0.0735, _
                            1.1)
    End Select


End Function

Now I want to give user a choice to select different type of aircraft from the same drop-down list to update say GPH() values without re-running the whole subroutine, i.e. only to update selected functions concerning aircraft parameters only after running the main sub.

How can I do that?! Namely, how can I activate the "plane" variable without running the main sub when I select a different type of aircraft from the menu?

Thank you!

Rustam
 
Last edited:

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top