+ Reply to Thread
Results 1 to 1 of 1

Run Time Error 5 Invalid Procedure Call or Argument

  1. #1
    Registered User
    Join Date
    06-28-2015
    Location
    Seattle, Washington
    MS-Off Ver
    2010
    Posts
    1

    Run Time Error 5 Invalid Procedure Call or Argument

    My program can't run because of run-time error '5' procedure call or argument. If I Google the term, I get websites that say that this type of error is caused by registry errors and you have to buy their product in order to fix it, is that true?

    Also, before my program broke down, I ran some test runs which worked. I changed a value on my spreadsheet and that's when the error started to occur. The error was intermittent for the next dozen runs, but eventually all runs now have the error. Since there had been successful runs with the same code before, I suspect that my file may be corrupted.

    The offending code is:

    'Calculate Production function
    Output_t1 = GrowthFactor ^ (Period_Length) * (Output_t0 + FactorProductivity * (1 - Damages_Production_t1) * _
    (1 - AbatementCost_Production) * (CapitalStock_t1 - CapitalStock_t0) ^ Share_K_Capital * _
    (Labor_t0 ^ Share_Labor))

    Specifically, the program does not like the term CapitalStock_t1 - CapitalStock_t0. I've tested every variable and every combination of variables, and the program only dislikes the term above, although once in awhile I'll get another run time 5 error in another statement. But generally, if I have CapitalStock_t1 or just CapitalStock_t0 in the statement, the program runs.

    If I use the term Output_t1 = CapitalStock_t1 - CapitalStock_t0 the program does not work. But it will work if I use Output_t1 = CapitalStock_t1 or Output_t1 = CapitalStock_t0. All combinations without the term CapitalStock_t1 - CapitalStock_t0 does work.


    To give the offending code more context, its embedded in a double loop - which could be the cause of the problem (there are also a lot of other subroutines, but the double loop is all in the main subroutine)

    Dim w As Long

    w = 1

    'Declare and set conditional statement variable
    Dim Abs_Error As Double

    Abs_Error = 0.1


    Do Until Abs_Error < 0.005

    'Assume Damages are equal to their last computed values
    Damages_CapitalStock_t1 = Damages_CapitalStock_t0
    Damages_Utility_t1 = Damages_Utility_t0
    Damages_Production_t1 = Damages_Production_t0
    Damages_Composite_t1 = Damages_Composite_t0


    'Calculate Capital Stock. Remember, damages to capital stock acts like another depreciation rate.
    CapitalStock_t1 = Investment_t0 + (1 - Dep_k) ^ Period_Length * (1 - Damages_CapitalStock_t0) ^ Period_Length * CapitalStock_t0

    'Calculate Production function
    Output_t1 = GrowthFactor ^ (Period_Length) * (Output_t0 + FactorProductivity * (1 - Damages_Production_t1) * _
    (1 - AbatementCost_Production) * (CapitalStock_t1 - CapitalStock_t0) ^ Share_K_Capital * _
    (Labor_t0 ^ Share_Labor))


    'Calculate World Accounting Equation: Consumption, Investment and Government Spending.

    Consumption_t1 = (Share_Consumption * Output_t1) * (1 - AbatementCost_Consumption) ^ (1 / (1 + MU_Elasticity))
    Investment_t1 = Share_Investment * Output_t1 + (1 - (1 - AbatementCost_Consumption) ^ (1 / (1 + MU_Elasticity)))
    Government_t1 = Share_Government * Output_t1
    TotalDeadWtLoss_t1 = Output_t1 - Consumption_t1 - Investment_t1 - Government_t1

    'Note: AtmoEmissions is the same as retained emissions.

    'Energy Balance
    Energy_Usage_Consumption_t1 = Energy_to_Consumption_Ratio * Consumption_t1
    Energy_Usage_Production_t1 = Energy_to_Production_Ratio * Output_t1
    Energy_Usage_t1 = Energy_Usage_Consumption_t1 + Energy_Usage_Production_t1
    AtmoEmissions_Consumption_t1 = Emissions_Consumption_Ratio * Consumption_t1
    AtmoEmissions_Output_t1 = Emissions_Output_Ratio * Output_t1
    AtmoEmissions_t1 = AtmoEmissions_Consumption_t1 + AtmoEmissions_Output_t1

    'CO2 Level
    CO2_Level_t1 = AtmoEmissions_t1 + (CO2_Equilibrium_Fraction_Atm * (CO2_Level_t0 - CO2_Equilibrium)) + _
    ((1 - CO2_Equilibrium_Fraction_Atm) * (1 - CO2_TransferRate_to_Atm) * (CO2_Level_t0 - CO2_Equilibrium)) + CO2_Equilibrium
    CO2_Transient_t1 = (1 - CO2_Equilibrium_Fraction_Atm) * AtmoEmissions_t1 + (1 - CO2_Equilibrium_Fraction_Atm) * _
    (1 - CO2_TransferRate_to_Atm) * (CO2_Level_t0 - CO2_Equilibrium)
    New_CO2_Equilibrium_t1 = CO2_Level_t1 - CO2_Transient_t1

    'New Temperature Deviation
    Dim Temp_Off_t1 As Double
    Temperature_Critical = Sheets(1).Range("K28")

    Forcing_t1 = 3.35 * (Log(1 + 1.2 * CO2_Level_t1 + 0.005 * CO2_Level_t1 ^ 2 + 1.4 * 10 ^ (-6) * CO2_Level_t1 ^ 3) _
    - Log(1 + 1.2 * CO2_Equilibrium + 0.005 * CO2_Equilibrium ^ 2 + 1.4 * 10 ^ (-6) * CO2_Equilibrium ^ 3))

    Temp_Off_t1 = ClimateSensitivity_Lambda * Forcing_t1
    If Temp_Off_t1 < Temperature_Critical Then
    Switch = 0
    Else
    Switch = 1
    End If

    Temp_t1 = Temp_Off_t1 + ClimateSensitivityParameter_b2 * Switch * (CO2_Level_t1 / CO2_Equilibrium)

    'Damages
    Damages_Utility_t1 = 1 - (1 / (1 + Proportional_Constant_Temperature_U * Temp_t1 + Exponent_Constant_Temperature_U * Temp_t1 ^ 2))
    Damages_Production_t1 = 1 - (1 / (1 + Proportional_Constant_Temperature_Y * Temp_t1 + Exponent_Constant_Temperature_Y * Temp_t1 ^ 2))
    Damages_CapitalStock_t1 = 1 - (1 / (1 + Proportional_Constant_Temperature_K * Temp_t1 + Exponent_Constant_Temperature_K * Temp_t1 ^ 2))
    Damages_Y_Composite_t1 = 1 - (1 - Damages_Production_t1) * (1 - Damages_CapitalStock_t1) ^ Share_K_Capital
    Damages_Composite_t1 = Damages_Utility_t1 + (1 - Damages_Utility_t1) * Damages_Utility_t1 * (Damages_Y_Composite_t1 ^ MU_Elasticity)


    'Begin Error Calculations
    'Termination or continuance condition of iteration process. If error is small enough terminate loop. Termination also occurs
    'when 100 iteration attempts have been made.


    If w = 1 Then
    Abs_Error = 0.001
    End If

    If w > 1 And w < 100 Then
    Abs_Error = Abs((Output_t1 - Output_t0) / Output_t0)
    End If

    If Abs_Error > 0.005 Then

    'Reset t1 variables as t0 variables and start at the beginning of the loop.

    Damages_Utility_t0 = Damages_Utility_t1
    Damages_Production_t0 = Damages_Production_t1
    Damages_Y_Composite_t0 = Damages_Y_Composite_t0
    Damages_Composite_t0 = Damages_Composite_t1

    End If

    'Termination or continuance condition of iteration process. If error is small enough terminate loop. Termination also occurs
    'when 100 iteration attempts have been made.

    w = w + 1


    Loop
    'End Inner Loop xxxxxxxxxxxxxxxxxxxxx'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx End Inner Loop
    End If


    'Utility and welfare calculations

    'Survivability Probability
    Survivability_Function_t1 = 1 - (Temp_t1 ^ 2 / (Temp_Max ^ 2 + 1.96 * (Temp_Max - Temp_t1) ^ 2))

    If Survivability_Function_t1 <= 0 Then
    Temp_t1 = SKI_Limit_Temp
    Survivability_Function_t1 = 0
    End If

    'Utility Index
    Raw_Utility_Index_t1 = (Survivability_Function_t1 * (Consumption_t1 ^ MU_Elasticity)) / MU_Elasticity
    Utility_Index_t1 = Utility_Normalization_Factor * Raw_Utility_Index_t1

    'Welfare
    Welfare_t1 = Welfare_t0 + Discount_Factor ^ Period_Length * Utility_Index_t1


    'Print output
    Sheets(1).Range("P" & 3 + t, "AK" & 3 + t).Value = _
    Array(Output_t1, CapitalStock_t1, Consumption_t1, Investment_t1, Government_t1, TotalDeadWtLoss_t1, _
    Energy_Usage_Consumption_t1, Energy_Usage_Production_t1, Energy_Usage_t1, AtmoEmissions_t1, CO2_Level_t1, _
    CO2_Transient_t1, New_CO2_Equilibrium_t1, Temp_t1, Damages_Utility_t1, Damages_CapitalStock_t1, Damages_Production_t1, _
    Damages_Y_Composite_t1, Damages_Composite_t1, Survivability_Function_t1, Utility_Index_t1, Welfare_t1)



    'Reset stock variables and survivability function
    Damages_CapitalStock_t0 = Damages_CapitalStock_t1
    Investment_t0 = Investment_t1
    CapitalStock_t0 = CapitalStock_t1
    Output_t0 = Output_t1
    CO2_Level_t0 = CO2_Level_t1
    Welfare_t0 = Welfare_t1
    Survivability_Function_t0 = Survivability_Function_t1

    t = t + 1

    Loop


    'End of outer loop VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV End of Outer Loop

    End Sub

    Anyone have any idea what could be wrong?
    Last edited by esong_98; 06-28-2015 at 08:26 PM. Reason: Additional statement

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run-time error '5' Invalid procedure call or argument
    By CCSlice in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-07-2015, 03:21 AM
  2. Help! Run-Time Error '5': Invalid procedure call or argument
    By capwork in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2015, 08:10 PM
  3. Run-time error 5, Invalid procedure call or argument
    By cmb80 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-23-2014, 08:29 AM
  4. Run-time error '5': Invalid procedure call or argument
    By mcbruce76 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 07-30-2013, 08:31 PM
  5. Replies: 2
    Last Post: 02-24-2006, 05:30 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1