• 376 views | 8 messages Discussion: LEAP
    Topic: Writing a code in Leap. (visual basic)Subscribe | Previous | Next
  • Ahmed Alaadin 12/27/2019

    How can I write a line in my code to change the value of a key assumption ?
    I wrote " Leap.Branch("Key Assumptions\Modeling Parameters").Variable("MaximumGrowth").Expression = Interp(2020,5%,2030,2.5%) "
    But it turned out an error "Typemismatch: Interp ". then I tried to set it to one value but also gave me an error ( shown in the attachment).
    Can you help me out?


    Leap.PNG
  • Charlie Heaps 1/7/2020
      Best Response

    >>How can I write a line in my code to change the value of a key assumption ? I wrote " Leap.Branch("Key Assumptions\Modeling Parameters").Variable("MaximumGrowth").Expression = Interp(2020,5%,2030,2.5%) "

    I'm assuming you have a key assumption branch named "maximum growth" under categories named "Key Assumptions\Modeling Parameters". As shown in attached image...

    If so you can write the VB like this:
    LEAP.Branches("Key Assumptions\Modeling Parameters\MaximumGrowth").Variable("Activity Level").Expression = "Interp(2020,5,2030,2.5)"

    A few things to note:
    1. Key assumptions are a bit odd in that they only have one variable named "Activity Level" and that variable is always implicit (not named) in LEAP's main screen. This may not have been my best design decision, but I'm afraid we are stuck with it now. Sorry!
    2. Note that "LEAP.Branch" is now deprecated. Please use LEAP.Branches instead.
    3. If your key assumption is specified in "%" units, and if it is itself measuring a growth rate, then you don't need to specify the % terms in your Interp expressions. Just write as a above. If you do write 5% then this will be interpreted as a value of 0.05. This is similar to how Excel works.
    4. Finally a tip: you can try out expressions with the script editor (menu option Advanced: Edit Scripts).

    I hope this helps!

    Charlie


    KeyParam.jpg
  • Ahmed Alaadin 2/4/2020
      Best Response

    Thank you so much. It worked.
    But when putting this line in a For loop to iterate on the values of the year 2030 , it reads the variable j of the loop as a string.

    FOR j= 5 to 10 step 0.1
    LEAP.Branches("Key Assumptions\Modeling Parameters\MaximumGrowth").Variable("Activity Level").Expression = "Interp(2020,5,2030, j)"
    NEXT

    Could you help me out?

  • Charlie Heaps 2/26/2020
      Best Response

    You need to write it like this:

    LEAP.Branches("Key Assumptions\Modeling Parameters\MaximumGrowth").Variable("Activity Level").Expression = "Interp(2020,5,2030, " & j & ")"



  • Ahmed Alaadin 2/28/2020
      Best Response

    Thank you so much.

    Can I ask about one more thing ?
    When I use the property value, the attached error pops up although it is written that this property can be written using one parameter (year) .
    And if I must write all 3 parameters what should I write in Unit name and filter ? Could you help me out ?

    Thank you.


    Capture.PNG
  • Charlie Heaps 2/28/2020
      Best Response

    Hi Ahmed - I don't have a theory on this one. It seems that LEAP "thinks" its processing an internal IF expression, but you code doesn't seem to show one. This could be a bug in LEAP. If you want to send me you data set (send to leap@sei.org attached as a .leap file). I can try and dig into it to find out what is going on. Please give me some time though as I am very busy this and next week.

    Charlie

  • Ahmed Alaadin 3/2/2020
      Best Response

    Ok no problem. I sent the Leap file and the script.
    Thank you so much Charles.

  • Ahmed Alaadin 4/15/2020
      Best Response

    Dear Charles

    I was just asking if the LEAP file and the script (I sent by mail) reached you .

    Thank you so much.