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]OFREAL;
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, I've managed to get a little bit futher. I've used the following to declare a Variable Input Constant:
VAR_INPUTCONSTANTΒ Β Data_Length:INT:=100;END_VAR
This in conjuction with:
FIFO_ARRAY:ARRAY[0..Data_Length]OFREAL;
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
However, the above returns an error of:
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
Ok, I've managed to get a little bit futher. I've used the following to declare a Variable Input Constant:
This in conjuction with:
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
YES
Thanks, but that doesn't help me very much, if you could expand on that just a little?
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.