Topic
  • 2 replies
  • Latest Post - ‏2013-07-29T11:55:10Z by Nicolas33
Nicolas33
Nicolas33
11 Posts

Pinned topic Functions, arrays and vectors in OPL script

‏2013-07-25T09:43:31Z |

Hello,

 

I have a question in OPL script, I would like to declare a vector of integer in a main script block (or an execute) is it possible?

I usually declare such arrays and a fixed size in preamble, but it is not possible in my case, because the size of the vector change..

Do you have a solution?

 

If I declare it in a function, is it a local variable that is suppressed after the end of the function?

Thanks,

nicolas

Updated on 2013-07-25T09:44:51Z at 2013-07-25T09:44:51Z by Nicolas33
  • AlexFleischer
    AlexFleischer
    1920 Posts

    Re: Functions, arrays and vectors in OPL script

    ‏2013-07-25T15:04:51Z  

    Hi,

     

    in scripting  when an element of an array is set beyond the current length of the array, the array is automatically expanded.

    main
    {
     var a=new Array(1);
     a[1]=2;
     writeln(a.length);
     a[5]=4;
     writeln(a.length);
    }

     

    gives

    2

    6

    You should have a look at

     

    in the documentation

  • Nicolas33
    Nicolas33
    11 Posts

    Re: Functions, arrays and vectors in OPL script

    ‏2013-07-29T11:55:10Z  

    Hi,

     

    in scripting  when an element of an array is set beyond the current length of the array, the array is automatically expanded.

    main
    {
     var a=new Array(1);
     a[1]=2;
     writeln(a.length);
     a[5]=4;
     writeln(a.length);
    }

     

    gives

    2

    6

    You should have a look at

     

    in the documentation

    Thank you very much!