Solved

Initializing parameters with property RetainsValue

  • 12 October 2020
  • 1 reply
  • 93 views

Badge

Is it possible to initialize local parameters, which have the property RetainsValue set? The first time, that the procedure/function is called, I would like the parameter to be initialized by a certain value. Afterwards, when the procedure/function is called again, I would like the parameter to keep the value from the previous procedure call.

If I set Initial data for the parameter, the behaviour of RetainsValue is lost and the parameters is initialized with that value in every call to the procedure.

icon

Best answer by gdiepen 13 October 2020, 10:34

View original

1 reply

Userlevel 5
Badge +7

Hi Benedikt,

 

Not sure if there is a way to directly combine the RetainsValue AND Initial data, but you could easily create a workaround by using another local parameter isAlreadyInitialized. This parameter should also have the property RetainsValue.

In the code your procedure, you first check the value of the isAlreadyInitalized. If the value is 0 (default value), it means that the procedure is being called for the first time and you initialize all your other local parameters to their initial value. After that, you set the value of the isAlreadyInitialized to the value 1 (which it will keep because of the RetainsValue).

Next time the procedure is called, the initialization will not be called anymore because the parameter has the value 1 now.

 

Reply


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator