Dimensional array table

LooijmansR
2019-11-15
2019-11-22
  • LooijmansR - 2019-11-15

    Hi,

    I need to show some user-specific data which is stored into a 3-dimensional array, like:

    userData : ARRAY[0..9,1..10,1..5] OF STRING;

    The data is stored this way, because it is SQL data which needs to be visualized for the user. The visualization table works fine with a 2-dimensional array, but refuses to work with a 3-dimensional array, even when in the data-field (in the visu) a 2-dimensional array is stored.

    Example:

    Variable:
    testData: ARRAY[1..10,1..5] OF STRING;

    Data-field:
    testData

    Works fine, but when the following is entered, it's not working as I intended it to work.

    Variable:
    userData : ARRAY[0..9,1..10,1..5] OF STRING;

    Data-field:
    userData[CURRENTCLIENTID]

    userData[CURRENTCLIENTID] really is a 2-dimensional array. So I have no idea why it would not work.

    I hope someone could tell me what I am doing wrong or what I should do different.

    Kind regards,
    Reno

     
  • m.prestel - 2019-11-15

    Hello Reno,

    could you provide a small example?

    Thx!

    Best regards,
    Marcel

     
  • LooijmansR - 2019-11-15

    Hi Marcel,

    Of course. See images attached

    Thanks in advance.

    Kind regards,
    Reno

    IMG: Untitled2.png

    IMG: Untitled.png

     
  • m.prestel - 2019-11-15

    Hello,

    that is not how the access to the array works, you need to specify the index of each dimension.

    You cannot do stuff like this:
    strMachineHistory := strMachineTest[0];

    What you really wanna do, is defining an array of array!

    Just keep in mind -1 is a valid ID for CURRENTCLIENTID (Better use the constants VISU_MIN_NUMBER_OF_CLIENTS and VISU_MAX_NUMBER_OF_CLIENTS)

    Best regards,
    Marcel

     
  • LooijmansR - 2019-11-15

    Hi Marcel,

    Thanks for the tip on VISU_MIN_NUMBER_OF_CLIENTS and VISU_MAX_NUMBER_OF_CLIENTS, I'm gonna edit that right away.

    Though, I'm not entirely sure what you're advising. If you're implying what I think you are, then that is not working either. See image attached.

    In any case, how would I best render a table with SQL data based on the visu user? I really thought a 3D array would be a good solution if I provided the client ID as the first index in the table data array.

     
  • m.prestel - 2019-11-18

    Hello,

    to make the configuration work you need to define strMachineTest like this

    strMachineTest : ARRAY[VISU_MIN_NUMBER_OF_CLIENTS ..VISU_MAX_NUMBER_OF_CLIENTS] OF ARRAY[0..5,1..10] OF STRING;

    If that is not what you are trying to do, then please describe your data a bit more and why/if it has really 3 dimensions.

    Best regards,
    Marcel

     
  • LooijmansR - 2019-11-22

    Hi Marcel,

    Thanks for your reply! That seems like it is the solution. Could you elaborate what the difference is between defining the dimensional variable like your proposed method and the definition below?

    strMachineTest := [0..1,0..5,1..10] OF STRING;

    Kind regards,
    Reno

     
  • m.prestel - 2019-11-22

    Hello Reno,

    please take a look at the online help.

    https://help.codesys.com/webapp/_cds_da ... n=3.5.15.0

    Especially the attached screenshot shows the difference between the two ways of defining an array really good.

    Best regards,
    Marcel

    IMG: Arrays.PNG

     
  • LooijmansR - 2019-11-22

    Hi Marcel,

    Perfect! Seems like I've been doing this the wrong way the majority of my time.. I will change the way of defining arrays to your suggestion. That seems way more appropriate. I was not aware this was possible.

    I should have read the docs better.. My bad.

    Thanks for your time!!

    Kind regards,
    Reno

     

Log in to post a comment.