arr_curr( )

During or immediately after the INPUT ARRAY or DISPLAY ARRAY statement the ARR_CURR( ) function returns the number of the program record within the program array that is displayed in the current line of a screen array, or the last active screen array if there is no current array.

 

Usage

 

The current line of a screen array is the line that displays the screen cursor at the beginning of a BEFORE ROW or AFTER ROW clause.

The ARR_CURR( ) function returns an integer value. The first row of the program array and the first line (that is, top-most) of the screen array are both numbered 1. The built-in functions ARR_CURR( ) and SCR_LINE( ) can return different values if the program array is larger than the screen array.

 

You can pass ARR_CURR( ) as an argument when you call a function. In this way the function receives as its argument the current record of whatever array is referenced in the INPUT ARRAY or DISPLAY ARRAY statement.

 

The ARR_CURR( ) function can be used to force a FOR loop to begin beyond the first line of an array by setting a variable to ARR_CURR( ) and using that variable as the starting value for the FOR loop.

 

The following program shows the differences between values returned by ARR_CURR( ) and SCR_LINE( ) functions.

The screen array defined in the form is 5 rows long. The program array defined in the 4gl is 20 rows long.

When a user moves to the 6th row by pressing "down arrow" key 5 times, the "Program array line" will be equal to 6 but the "Form array line" will remain equal to 5 because the screen array limit of 5 rows is reached.

Then, when a user moves up by pressing "up arrow" key, the "Program array line" will be equal to 5 and the "Form array line" will be equal to 4 because the user moved up one line on the screen array.

 

MAIN

  DEFINE arr1 ARRAY[20] OF RECORD

    f1 CHAR(10),

    f2 CHAR(10),

    f3 CHAR(10)

    END RECORD

  DEFINE i, j INTEGER

 

  OPEN WINDOW w_test

    AT 2, 2

    WITH FORM "arr_curr_function"

 

  FOR i = 1 TO 20

    LET arr1[i].f1 = "Row ", i USING "<&"

    LET arr1[i].f2 = "Column 2"

    LET arr1[i].f3 = "Column 3"

  END FOR

 

  CALL set_count(20)

 

  DISPLAY ARRAY arr1 TO sc_rec.*

    BEFORE ROW

      LET i = arr_curr()

      LET j = scr_line()

      DISPLAY i TO f_arr_curr

      DISPLAY j TO f_scr_line

  END DISPLAY

 

  CLOSE WINDOW w_test

END MAIN

 

The ARR_CURR( ) function is frequently used with a DISPLAY ARRAY statement in popup windows to return the user’s selection.

 

Form File: arr_curr_function.per

 

DATABASE formonly

 

SCREEN

{                                                                          

  [f1      ] [f2         ] [f3         ]                                      

  [f1      ] [f2         ] [f3         ]                                      

  [f1      ] [f2         ] [f3         ]                                      

  [f1      ] [f2         ] [f3         ]                                      

  [f1      ] [f2         ] [f3         ]                                      

                                                                              

     Program\g \gArray\g \gLine   [f16 ]                                              

     Form\g \gArray\g \gLine      [f17 ]                                              

                                                                                                                                                              

}

 

ATTRIBUTES

f1=formonly.f1;

f2=formonly.f2;

f3=formonly.f3;

f16=formonly.f_arr_curr;

f17=formonly.f_scr_line;

 

INSTRUCTIONS

SCREEN RECORD sc_rec[5]  (

      formonly.f1,

      formonly.f2,

      formonly.f3

      )

 

DELIMITERS "[]"   

 

References

ARR_COUNT( ), SCR_LINE( )