Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dimension or declare array

Status
Not open for further replies.

SnyAc

Programmer
Jul 25, 2001
272
US
I have found a situation where an array is being created using AFIELDS() and then re-dimensioned larger to add fields to the array in order to create a temporary table with the additional fields. VFP9 seems to want to clear the array when it is re-dimensioned (all elements set to logical false) so the subsequent CREATE TABLE FROM ARRAY fails with a syntax error.

Any ideas on why the array would get re-initialized on the re-dimension?



Andy Snyder
SnyAc Software Services
 
The newly added array elements will have initial values of logical False, but the original array element values should not be disturbed when the array is redimensioned. The following code does what I think you're describing and leaves the first set of array elements as is:

Code:
CREATE TABLE myTable ( cField1 c(10))
AFIELDS( laFields, "myTable")
DISPLAY MEMORY LIKE laFields && Array is [1,18] with values as expected
DIMENSION laFields(2,18)
DISPLAY MEMORY LIKE laFields && Original array values are still intact

Is it possible in your situation that a different array is being created or the original array is going out of scope?

-Rick
 
FYI - you need to copy the link to Mike's article (including the equals sign at the end) and paste it into your browser as the automatic linking hasn't included the equals sign.

Stewart
 
What you need to do is create another array, the size you need and then copy your data into it... at least that is what I would do.

Regards

Griff
Keep [Smile]ing
 
>>Any ideas on why the array would get re-initialized on the re-dimension?

Yes. Check the setting of SET COMPATIBLE.

IF it is ON (dBase) then arrays are re-initialized when re-dimensioned, if it is OFF (VFP) then they are not.

This is documented behavior - see the DECLARE command for details.

As an aside, SET COMPATIBLE ON is a setting that should NEVER be used in VFP - it affects the behavior of all sorts of things - see the Help file for the full list.

It was included in the language when dBase was a major competitor for FoxPro to enable dBase code to run directly. It has no other function or use but it does mess up VFP behaviors.


----
Andy Kramek
Visual FoxPro MVP
 
Andy... I think you hit the nail on the head. This is a complex app that includes a good bit of old legacy code. I am in the process of updating this application to get it ready for release in VFP9 format. I changed the use of afields() to an SQL select with no records to create the read-write cursor.

Thanks again for everyone's input.... always helpful.

Andy Snyder
SnyAc Software Services
 
Is anyone else having problems posting here? I cannot post anything

----
Andy Kramek
Visual FoxPro MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top