Is it possible to change array size at runtime in KUKA KRL programming language? Is it possible to mimic the behavior of List from C#?
It is not possible to change the size of arrays in KUKA KRL, nor is it possible to dynamically set the size of an array, such as with a variable in the declaration like:
DECL INT test_array[i]
Arrays must be pre-allocated. If you aren't sure how many elements you need to store, then its best to pre-allocate the array with a large number that you feel certain won't overflow.
You cannot use list like behavior with arrays, so no Add or Find, etc. Its bare bones assignments to explicit indices.
You CAN do multi-dimension arrays, such as this:
DECL CHAR dog_names[5,32]
dog_names[1,] = "spot"
dog_names[2,] = "buddy"
DECL INT my_matrix[4,4]
my_matrix[4,2] = 6
You can also make an array of STRUCs, which are as close to an object as you get in KRL. STRUCs in KRL work similarly to structures in other programming languages.
ENUM PERMS admin, maint, user
STRUC SYSTEM_USER CHAR[32] first_name, last_name, REAL age, height, PERMS user_perm
DECL STRUC my_employees[10]
my_employees[1].first_name[] = "Sarah"
my_employees[1].last_name[] = "blahblah"
my_employees[1].age = 33
my_employees[1].height = 105
my_employees[1].user_perm = #admin
my_employees[2] = {first_name[] "Lester", user_perm = #maint}