PRB: SET COMPATIBLE ON Causes Problems with Arrays

ID: Q184969


The information in this article applies to:
  • Pro Edition of Microsoft Visual FoxPro for Windows, versions 3.0, 3.0b
  • Microsoft Visual FoxPro for Windows, versions 5.0, 5.0a
  • Pro Edition of Microsoft Visual FoxPro for Mac, version 3.0


SYMPTOMS

If SET COMPATIBLE is ON and an array is redimensioned, the array loses it previously saved values and sets the current value to logical false (.F.).


CAUSE

When SET COMPATIBLE is set to ON or DB4, Visual FoxPro overwrites any existing array with a variable of the same name when a STORE command or assignment is made.


RESOLUTION

If the array needs to retain its contents, try one of the following:

  • Issue SET COMPATIBLE OFF in the program or form.


  • Add COMPATIBLE=OFF to the Config.fpw file.


  • From the Tools menu, select Options. In the Options dialog box, click the General tab and clear the dBase compatibility check box.



STATUS

This behavior is by design.


MORE INFORMATION

Steps to Reproduce Behavior

This can be demonstrated when an array is redimensioned within a loop. To reproduce the problem, create a new program and enter the following code:

   CLEAR
   SET COMPATIBLE ON         && Or SET COMPATIBLE DB4
   DIMENSION atest(5)     && Dimension to some value.
   FOR i = 1 to 10
      DIMENSION atest(i)
      Atest(i)="Test "+ALLTRIM(STR(i))
   ENDFOR

   DISPLAY MEMORY LIKE atest 
When the code is executed, the array has 10 elements, but only the last element contains a value. The other elements contain a logical false (.F.).

© Microsoft Corporation 1998, All Rights Reserved.
Contributions by Dean Christopher, Microsoft Corporation


REFERENCES

Visual FoxPro 3.x for Windows Help; search on: SET COMPATIBLE and STORE
Visual FoxPro 3.0b for Macintosh Help; search on: SET COMPATIBLE and STORE
Visual FoxPro 5.x for Windows Help; search on: SET COMPATIBLE and STORE
Visual FoxPro 3.x for Windows, "Language Reference", pages 756 and 794.
Visual FoxPro 5.x for Windows, "Language Reference", pages 379 and 403.
Visual FoxPro 3.0b for Macintosh, "Language Reference", pages 803 and 843.

Additional query words:

Keywords : kbMAC kbVFp FxprgGeneral FxprgSet
Version : MACINTOSH:3.0; WINDOWS:3.0,3.0b,5.0,5.0a
Platform : MACINTOSH WINDOWS
Issue type : kbprb


Last Reviewed: December 10, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.