Home AMX User Forum NetLinx Studio

Multidimensional arrays to functions

Greetings!

I have a trouble in using function with 4-dimensional array:

define_variable
persistent integer DATA_HOURS[YEARS][MONTHES][DAYS][HOURS]
...
PROCESS_GRAPH(DATA_HOURS[VIEW_YEAR][VIEW_MONTH][VIEW_DATE],length_data)

Function gets an emty array. When I'm trying to copy data into a single dimension array, I get an emty array too:

FOR(I=1;I<=LENGTH_DATA;I++)
DRAW_DATA=DATA_HOURS[VIEW_YEAR][VIEW_MONTH][VIEW_DATE]

But in Debug Watch window I see that array DATA_HOURS is not empty.

Why it happens?

Comments

  • What does your define_function look like for PROCESS_GRAPH?
  • depsdeps Posts: 27
    rfletcher wrote: »
    What does your define_function look like for PROCESS_GRAPH?

    DEFINE_FUNCTION PROCESS_GRAPH(INTEGER gDATA_ARRAY[], integer N_DATA)
  • nickmnickm Posts: 152
    In these scenarios, I find it easier to put the data into a structure and pass a structure object into the function. It may be a bit more work to modify what you already have in place. Just my 2 cents.
  • champchamp Posts: 261
    My guess is that you are populating the array one byte at a time and the length of the array is still zero.
    Put the following line in PROCESS_GRAPH() to debug it:

    SEND_STRING 0, "'PROCESS_GRAPH, LENGTH_ARRAY(gDATA_ARRAY)=', ITOA(LENGTH_ARRAY(gDATA_ARRAY))";

    If this is the problem then use the command SET_LENGTH_ARRAY before calling PROCESS_GRAPH()
  • depsdeps Posts: 27
    champ wrote: »
    My guess is that you are populating the array one byte at a time and the length of the array is still zero.
    Put the following line in PROCESS_GRAPH() to debug it:

    SEND_STRING 0, "'PROCESS_GRAPH, LENGTH_ARRAY(gDATA_ARRAY)=', ITOA(LENGTH_ARRAY(gDATA_ARRAY))";

    If this is the problem then use the command SET_LENGTH_ARRAY before calling PROCESS_GRAPH()

    When using SET_LENGTH_ARRAY, length of gDATA_ARRAY is 24, but array consists of zeroes.

    length_data=24
    SET_LENGTH_ARRAY(DATA_BASE_HOURS[VIEW_YEAR][VIEW_MONTH][VIEW_DATE], LENGTH_DATA)
    SET_LENGTH_ARRAY(DRAW_DATA, LENGTH_DATA)

    FOR(I=1;I<=LENGTH_DATA;I++)
    DRAW_DATA=DATA_BASE_HOURS[VIEW_YEAR][VIEW_MONTH][VIEW_DATE]
    PROCESS_GRAPH( DRAW_DATA,length_data)
  • depsdeps Posts: 27
    Program works on firmware v4_1_373 (NI4100)

    Thanks for help!
Sign In or Register to comment.