Microsoft KB Archive/106277

{| = How to Refresh Array Values on a Screen =
 * width="100%"|

ID: Q106277

2.50 2.50a 2.50b | 2.00 2.50 2.50a 2.50b

WINDOWS              | MS-DOS The information in this article applies to:
 * Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b
 * Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b

SUMMARY
When you use an array structure to display values on a screen with the @ ... GET command, you cannot change or rereference the subscript of the array to display different elements or values on the screen. The definition of the GET object is initialized in memory as the array element based on the subscript that is first used.

You can display additional array elements. However, you must use two arrays, one that holds the data and one that defines and holds the contents of the GET objects.

Below are three programs that illustrate the difference. The first example does not display the correct values of the array elements after you press the PAGE DOWN key. The second example correctly displays the array elements incrementally as you press the PAGE DOWN key. The third example shows how to display array values by assigning the GET field to a variable that references the array.

Program 1
In this program, the subscript for the array "myarray1" is incremented. This is the array that is displayed on the screen with the @ ... GET command. The procedure "pagedown" is called when the PAGE DOWN key is pressed. This code does not display the correct values after the procedure is called. The variable "x" is incremented, as can be observed in the Debug window. However, the elements are not refreshed on the screen as expected.

PUBLIC x                         && Declare variable x public. ON KEY LABEL pgdn DO pagedown    && Define the PAGE DOWN key event. DIMENSION myarray1(6)            && Create an array. myarray1(1) = "Blue "            && Initialize the array elements. myarray1(2) = "Green " myarray1(3) = "Red  " myarray1(4) = "Yellow" myarray1(5) = "Orange" myarray1(6) = "White " x=1                              && Initialize subscript. @ 1,1 GET myarray1(x)            && Define the GET objects. @ 2,1 GET myarray1(x+1)          && Position on the screen. @ 3,1 GET myarray1(x+2) READ CYCLE                       && Activate READ level.

PROCEDURE pagedown               && Procedure that is called when x=x+1                         && the PAGE DOWN key is pressed. SHOW GETS                     && Redisplay the GET objects. RETURN                           && Return to the calling program.

Program 2
This second program works as expected when two arrays are used. The subscript for the array that is displayed for the @ ... GET objects, "myarray2", is never incremented. Instead, the original array subscript, "myarray1", is incremented. The contents of "myarray2" are reassigned the values from "myarray1" as the subscript is incremented in the "pagedown" procedure. The values or elements of the array that are displayed on the screen change each time the PAGE DOWN key is pressed.

ON KEY LABEL pgdn DO pagedown    && Define the PAGE DOWN key event. DIMENSION myarray1(6)            && Create two arrays. DIMENSION myarray2(3) myarray1(1) = "Blue "            && Initialize the data array. myarray1(2) = "Green " myarray1(3) = "Red  " myarray1(4) = "Yellow" myarray1(5) = "Orange" myarray1(6) = "White " x=1                              && Initialize subscript. myarray2(1)=myarray1(x)          && Initialize the display array myarray2(2)=myarray1(x+1)        && with values from data array. myarray2(3)=myarray1(x+2) @ 1,1 GET myarray2(1)            && Define the GET objects. @ 2,1 GET myarray2(2)            && Position on the screen. @ 3,1 GET myarray2(3) READ CYCLE                       && Activate READ level.

PROCEDURE pagedown               && Procedure that is called when IF (x <= 3)                   && the PAGE DOWN key is pressed. x=x+1                      && Increment the subscript. myarray2(1)=myarray1(x)    && Assign display array values myarray2(2)=myarray1(x+1)  && from data array. myarray2(3)=myarray1(x+2) SHOW GETS                  && Redisplay the GET objects. ELSE WAIT WINDOW "End of Array" && Message to user. ENDIF RETURN                           && Return to the calling program.

Program 3
When you create the GET field for the screen, assign it to a variable that references the array, instead of assigning it to the array itself. Issuing a SHOW GETS command updates the variable based on the array.

For example, use the following screen setup:

DIMENSION myarray(3) myarray(1) = 'Apples' myarray(2) = 'Bananas' myarray(3) = 'Cantaloupe' x=3 vararray = myarray(x)

GET FIELD = vararray Change the subscript for the array by simply incrementing x up or down. Then set vararray = myarray(x) and issue a SHOW GETS command to update the GET field. NOTE: This example does not take into account how to allow an update to the GET field or how to add elements to the array.