Difference between revisions of "Microsoft KB Archive/106277"

From BetaArchive Wiki
m (Text replacement - "<" to "<")
m (Text replacement - "&" to "&")
 
Line 27: Line 27:
 
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.
 
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.
  
<pre>  PUBLIC x                          &amp;&amp; Declare variable x public.
+
<pre>  PUBLIC x                          && Declare variable x public.
   ON KEY LABEL pgdn DO pagedown    &amp;&amp; Define the PAGE DOWN key event.
+
   ON KEY LABEL pgdn DO pagedown    && Define the PAGE DOWN key event.
   DIMENSION myarray1(6)            &amp;&amp; Create an array.
+
   DIMENSION myarray1(6)            && Create an array.
   myarray1(1) = "Blue  "            &amp;&amp; Initialize the array elements.
+
   myarray1(1) = "Blue  "            && Initialize the array elements.
 
   myarray1(2) = "Green "
 
   myarray1(2) = "Green "
 
   myarray1(3) = "Red  "
 
   myarray1(3) = "Red  "
Line 36: Line 36:
 
   myarray1(5) = "Orange"
 
   myarray1(5) = "Orange"
 
   myarray1(6) = "White "
 
   myarray1(6) = "White "
   x=1                              &amp;&amp; Initialize subscript.
+
   x=1                              && Initialize subscript.
   @ 1,1 GET myarray1(x)            &amp;&amp; Define the GET objects.
+
   @ 1,1 GET myarray1(x)            && Define the GET objects.
   @ 2,1 GET myarray1(x+1)          &amp;&amp; Position on the screen.
+
   @ 2,1 GET myarray1(x+1)          && Position on the screen.
 
   @ 3,1 GET myarray1(x+2)
 
   @ 3,1 GET myarray1(x+2)
   READ CYCLE                        &amp;&amp; Activate READ level.
+
   READ CYCLE                        && Activate READ level.
  
   PROCEDURE pagedown                &amp;&amp; Procedure that is called when
+
   PROCEDURE pagedown                && Procedure that is called when
       x=x+1                          &amp;&amp; the PAGE DOWN key is pressed.
+
       x=x+1                          && the PAGE DOWN key is pressed.
       SHOW GETS                      &amp;&amp; Redisplay the GET objects.
+
       SHOW GETS                      && Redisplay the GET objects.
   RETURN                            &amp;&amp; Return to the calling program.
+
   RETURN                            && Return to the calling program.
 
</pre>
 
</pre>
 
=== Program 2 ===
 
=== Program 2 ===
Line 51: Line 51:
 
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.
 
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.
  
<pre>  ON KEY LABEL pgdn DO pagedown    &amp;&amp; Define the PAGE DOWN key event.
+
<pre>  ON KEY LABEL pgdn DO pagedown    && Define the PAGE DOWN key event.
   DIMENSION myarray1(6)            &amp;&amp; Create two arrays.
+
   DIMENSION myarray1(6)            && Create two arrays.
 
   DIMENSION myarray2(3)
 
   DIMENSION myarray2(3)
   myarray1(1) = "Blue  "            &amp;&amp; Initialize the data array.
+
   myarray1(1) = "Blue  "            && Initialize the data array.
 
   myarray1(2) = "Green "
 
   myarray1(2) = "Green "
 
   myarray1(3) = "Red  "
 
   myarray1(3) = "Red  "
Line 60: Line 60:
 
   myarray1(5) = "Orange"
 
   myarray1(5) = "Orange"
 
   myarray1(6) = "White "
 
   myarray1(6) = "White "
   x=1                              &amp;&amp; Initialize subscript.
+
   x=1                              && Initialize subscript.
   myarray2(1)=myarray1(x)          &amp;&amp; Initialize the display array
+
   myarray2(1)=myarray1(x)          && Initialize the display array
   myarray2(2)=myarray1(x+1)        &amp;&amp; with values from data array.
+
   myarray2(2)=myarray1(x+1)        && with values from data array.
 
   myarray2(3)=myarray1(x+2)
 
   myarray2(3)=myarray1(x+2)
   @ 1,1 GET myarray2(1)            &amp;&amp; Define the GET objects.
+
   @ 1,1 GET myarray2(1)            && Define the GET objects.
   @ 2,1 GET myarray2(2)            &amp;&amp; Position on the screen.
+
   @ 2,1 GET myarray2(2)            && Position on the screen.
 
   @ 3,1 GET myarray2(3)
 
   @ 3,1 GET myarray2(3)
   READ CYCLE                        &amp;&amp; Activate READ level.
+
   READ CYCLE                        && Activate READ level.
  
   PROCEDURE pagedown                &amp;&amp; Procedure that is called when
+
   PROCEDURE pagedown                && Procedure that is called when
       IF (x <= 3)                    &amp;&amp; the PAGE DOWN key is pressed.
+
       IF (x <= 3)                    && the PAGE DOWN key is pressed.
         x=x+1                      &amp;&amp; Increment the subscript.
+
         x=x+1                      && Increment the subscript.
         myarray2(1)=myarray1(x)    &amp;&amp; Assign display array values
+
         myarray2(1)=myarray1(x)    && Assign display array values
         myarray2(2)=myarray1(x+1)  &amp;&amp; from data array.
+
         myarray2(2)=myarray1(x+1)  && from data array.
 
         myarray2(3)=myarray1(x+2)
 
         myarray2(3)=myarray1(x+2)
         SHOW GETS                  &amp;&amp; Redisplay the GET objects.
+
         SHOW GETS                  && Redisplay the GET objects.
 
       ELSE
 
       ELSE
         WAIT WINDOW "End of Array"  &amp;&amp; Message to user.
+
         WAIT WINDOW "End of Array"  && Message to user.
 
       ENDIF
 
       ENDIF
   RETURN                            &amp;&amp; Return to the calling program.
+
   RETURN                            && Return to the calling program.
 
</pre>
 
</pre>
 
=== Program 3 ===
 
=== Program 3 ===

Latest revision as of 12:24, 21 July 2020

How to Refresh Array Values on a Screen

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.

MORE INFORMATION

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.

REFERENCES

For more information about arrays, see the "Developer's Guide," version 2.5, pages D9-1 through D9-14.

Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a 2.50b KBCategory: KBSubcategory: FxtoolDebug

Keywords          : kbcode FxtoolDebug 
Version           : 2.50 2.50a 2.50b | 2.00 2.50 2.5
Platform          : MS-DOS WINDOWS

Last Reviewed: May 22, 1998
© 1999 Microsoft Corporation. All rights reserved. Terms of Use.