Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dirty trick of the day: ACOPY()
Message
From
01/04/2000 02:09:58
Walter Meester
HoogkarspelNetherlands
 
 
To
All
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Dirty trick of the day: ACOPY()
Miscellaneous
Thread ID:
00353860
Message ID:
00353860
Views:
45
Hi all,

When working with arrays you can simple assign a value to each element with STORE or = :
DIMENSION aArray[366,3]
STORE 0 TO aArray
At regular times I wished that I could qiuckly store different values for each column or just store a repeating patern in an array. You can make a loop to assign a value to each element, but i've found an easier and far more faster solution:
DIMENSION aArray[366,3]
aARRAY[1,1] = 1
aARRAY[1,2] = 2
aARRAY[1,3] = 3

ACOPY(aArray, aArray, 1, (366 - 1) * 3, 4)
The trick thus is to copy the array into itself where the destination element is equal to the source shifted by the length of the repeating values.

BTW. For all performance freaks:
DIMENSION aArray[366,3]
aArray=[0]
ACOPY(aArray, aArray, 1, (366*3) -1, 2)
also seems to be significatly faster than:
DIMENSION aArray[366,3]
STORE 0 TO aArray
Walter,
Next
Reply
Map
View

Click here to load this message in the networking platform