Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
AINS() doesn't work?
Message
From
08/12/2004 20:25:15
 
 
To
08/12/2004 10:54:49
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00967750
Message ID:
00967912
Views:
9
>From the help file:
>Inserting an element, row, or column into an array does not change the size of the array. The trailing elements, rows, or columns are shifted toward the end of the array and the last element, row, or column in the array is dropped from it. The newly inserted element, row, or column is initialized to false (.F.).
>
>What you should do is to make sure that the array is large enough before AINS:
DIMENSION aMyarray [2, 11]
>aMyarray = "ABC"
>AINS (aMyarray, 10, 2)
HTH
>
>>I want to insert a new column to a existing 2-dimensional array. I used the foxpro function aIns() to do this:
>DIME aMyarray[2,10]
>>aMyarray = "ABC"
>>=aIns(aMyarray,10,2)
>The result is that the aMyarray[2,10] becomes the new value .F. instead of inserting a new column into this array.

Just a warning to be careful with this.
If myArray is 2,3 as follows
1A  1B  1C
2A  2B  2C
and you DIME it to 2,4 you will get
1A  1B  1C  2A
2B  2C  .F. .F.
When you then insert a new column , =AINS(myArray,3,2) for example you get
1A  1B  .F. 1C
2B  2C  .F. .F.
I believe I have seen some posts here a while ago which went into this in more depth.

Here's a little routine which inserts a new empty(.F.) column into an array
PROCEDURE ins_new_column
LPARAMETERS taOldArray,tnNewColumn
lnOldRows = ALEN(taOldArray,1)
lnOldCols = ALEN(taOldArray,2)
lnNewCols = lnOldCols + 1
DIME taOldArray[lnOldRows*lnNewCols]
FOR I = 0 TO lnOldRows-1
	=AINS(taOldArray,tnNewColumn + (I*lnNewCols))
ENDFOR
DIME taOldArray[lnOldRows,lnNewCols]
so that INS_NEW_COLUMN myArray,3 would result in
1A   1B  .F.  1C
2A   2B  .F.  2C
Previous
Reply
Map
View

Click here to load this message in the networking platform