Enlarging arrays?

shrimper

Member
Join Date
Jun 2015
Location
Warsaw
Posts
4
Hi,

how would you enlarge an array?

I need to do a project with following visualization:
- text field, where user inputs data
- button, which user hits when he is done writing
- combo text field, which displays some data, and after the button is hit, value of text field is added to this data as new value (new cell of the array data)

User will be able to add data multiple times. Which means program must add a new cell to data array every time he hits the button. How do I accomplish that?

Regards,
shrimper
 
I'm not aware of any PLCs that can dynamically change the size of arrays without a program change. Memory allocation is,for the most part, static and "hard-wired" in the program. Generally you have to set an array size to the maximum that your application will require.
 
I've seen cases where programmers used arrays much larger than expected, and then separately tracked how many values were currently in the array. Everything unused was just left at the default empty/zero state.

Personally, I'm really glad that PLCs have statically assigned memory. Dynamic memory issues like memory leaks are at the heart of so many of the PC related problems we have.
 
As jstolaruk says, PLC's can't dynamically change the size of the arrays at runtime. You have to just create them large enough to handle the maximum amount of data. My rule of thumb is "think of a number, and then double it" :)

Then you just have to deal with checking whether each array element is used or not, and checking if there are any spares and advising the operator if not. If you created a warning for say, only 5 array elements left, that should in most applications give you enough warning to schedule a download to increase the size of your array.
 
I've seen cases where programmers used arrays much larger than expected, and then separately tracked how many values were currently in the array. Everything unused was just left at the default empty/zero state.

Are they ever empty though after creation? An array[100] of DINTs with a value >0 in the first 5 and zero in the last 95 - will it take up the same memory as if they didn't contain the value zero?
 
Are they ever empty though after creation? An array[100] of DINTs with a value >0 in the first 5 and zero in the last 95 - will it take up the same memory as if they didn't contain the value zero?

Yes...A value of 0 or XXXXXXX still takes the same amount of bytes of memory.
 

Similar Topics

Hi. This is pretty basic but I'm struggling to find an efficient solution. I have a float value of let say 666.555 that I want to move / split...
Replies
3
Views
198
Hello. I've been using the answers in this forum for a while now, so thank you. Usually I can find the answer I'm looking for with a basic...
Replies
8
Views
741
Hello, first time poster here! A belated "thank you" for the direction I've already received from this forum! So, can I do this? Move value 1...
Replies
6
Views
707
My first real attempt at utilising the AOI function in Compactlogix. The issue I'm having is, I have an array of INT[400], but in my AOI I'm only...
Replies
1
Views
450
Is there a way in CX-Programmer to initialise an array? Set all values to zero or false depending on the data type Solutions in Ladder and...
Replies
2
Views
1,254
Back
Top Bottom