Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Append to an array
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00254692
Message ID:
00254743
Views:
17
>Hello to all:
>I want to know if exist a function that appends a set of values into an array.
>Something as "scatter to", but that not delete the previous values of the array.

It's a little kludgey, but it can be done. Try the following:

Take the existing array and figure out the current number of of elements, rows and columns, Do a SQL Select to extract the records you need into a new array.

Redimension the old array to add the number of rows indicated by _TALLY for the number of records extracted. This will preserve your old data in the array, and create new rows with the new array members initialized to .F.

USE ACOPY to copy the new data into the old array, telling ACOPY to start copying into the destination array at original number of elements + 1. the new rows will be added at the end of the exisitng array.

An untested UDF for 2 imensiona; arrays might look like:
FUNCTION AppendArray
LPARAMETERS taOriginalArray, taNewElements
IF TYPE('taOriginalArray[1]') = 'U' OR ;
   TYPE('taNewElements[1]' = 'U'
   RETURN .F.
ENDIF
LOCAL nOldElems, nOldRows, nOldCols
nOldElems = ALEN(taOriginalArray,0)
nOldRows = ALEN(taOriginalArray,1)
nOldCols = ALEN(taOriginalArray,2)
DIMENSION taOriginalArray[nOldRows + ALEN(taNewElements,1), nOldCols]
=ACOPY(taNewElements,taOriginalArray,1, -1, nOldElems + 1)
RETURN .T.
I'd want to add some more error checking to make sure tha the number of columns in each array was the same, and that you didn't try to make an array with more elements than VFP will alllow. You may run into memory issues with big arrays.

In general, if the number of columns is known and the data type for each column is the same for all rows, using a cursor rather than an array may be lots easier in the long run. Also, look into SCATTER/GATHER...NAME, which creates an object that matches the fields; maintaining a 1 dimensional array of objects may be easier in the long run, too.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Reply
Map
View

Click here to load this message in the networking platform