Dynamic Array's

Alvxx1
2016-03-17
2016-03-20
  • Alvxx1 - 2016-03-17

    Firstly, sorry if this has been asked before but I can't find an answer that suits my needs.

    Im looking to define an Array, where the length of the Array is a variable. Something like this:

    Β  Β Dyn_Array: ARRAY[0..X] OF REAL;
    

    However, the above returns an error of:

    Zitat:
    Error 3750: PLC_PRG (10): Upper Bound 'X' not defined

    This also happens even if 'X' is defined and given a value in the declaration section.

    Is this possible, or am I missing something? I've got a custom First In First Out FB that i'd like to be able to specify the length of the Array in the block instead of having to import it from the library and edit it each time.

    Thanks

     
  • Alvxx1 - 2016-03-17

    Ok, I've managed to get a little bit futher. I've used the following to declare a Variable Input Constant:

    VAR_INPUT CONSTANT
    Β  Β Data_Length:INT:=100;
    END_VAR
    

    This in conjuction with:

    FIFO_ARRAY: ARRAY[0..Data_Length] OF REAL;
    

    Compiles correctly! Now this is great, because I can change the Data_Length constant and change the size of the Array.

    I assumed the because it was an "Input Variable" that I would be able to programmatically edit this value by passing a parameter to "{FunctionBlock}.Data_Length", but because a constant is exactly just that, no matter what I put for this parameter, it stays at 100.

    Is this as far as I can go, or is there still some hope at being able to pass this value to individual instances of a Function Block to vary that function block's array length.

    Thanks

     
  • shooter - 2016-03-20

    YES

     
  • Alvxx1 - 2016-03-20

    shooter hat geschrieben:
    YES

    Thanks, but that doesn't help me very much, if you could expand on that just a little?

     
  • shooter - 2016-03-20

    no sorry you can not change the size of arrays, as it would mean the memory has to shift a lot.
    you will have to design the max size, and maybe use just a little portion of it.
    In V3 it is possible on some machines.

    and obvious you can use different numbers when defing the function block instance, as long as it is a constant.
    the memory is allocated using this constant, and can not be changed.
    I never see a reason to change a size in a running program.

    please have a look at w www.oscat.de w (its english) for a big set of functions.

     

Log in to post a comment.