Even though ains(...,...,2) reportedly can add a column to an existing
array, I don't quite see how to do it. Given an array dimensioned [3,2] for
instance, what commands would I use to add a column so the resulting array
would have dimensions [3,3] and the contents of cols 1 & 2 would remain
intact?

--
-Lew
The workers took the robot for Maria.

Re: How to ains(xx,xx,2) a new column by Man-wai

Man-wai
Sun Aug 20 20:18:47 CDT 2006

Lew wrote:
> Even though ains(...,...,2) reportedly can add a column to an existing
> array, I don't quite see how to do it. Given an array dimensioned [3,2] for
> instance, what commands would I use to add a column so the resulting array
> would have dimensions [3,3] and the contents of cols 1 & 2 would remain
> intact?
>

You are expanding the dimension of the array, not adding a row. I would
try DECLARE your_array[3,3] to redefine the array first.

--
SoftMedia Technology Co., Ltd.
Website: http://www.softmedia.hk Tel: (852)2743 4228
* TryEasy Accounting/POS/Trading/ERP solutions

Re: How to ains(xx,xx,2) a new column by Jack

Jack
Sun Aug 20 23:42:08 CDT 2006

On Sun, 20 Aug 2006 16:28:20 -0400, "Lew" <lew@fastmail.fm> wrote:

>Even though ains(...,...,2) reportedly can add a column to an existing
>array, I don't quite see how to do it. Given an array dimensioned [3,2] for
>instance, what commands would I use to add a column so the resulting array
>would have dimensions [3,3] and the contents of cols 1 & 2 would remain
>intact?

I have never found a way to make it work. I copy the array,
redimension it, then copy the appropriate elements back.

Re: How to ains(xx,xx,2) a new column by Lew

Lew
Mon Aug 21 08:35:39 CDT 2006

...exactly my experience, too.
"Jack Jackson" <jacknospam@pebbleridge.com> wrote in message
news:rqdie2l759pn0vu5g1kcrhdedveql2tkvj@4ax.com...
> On Sun, 20 Aug 2006 16:28:20 -0400, "Lew" <lew@fastmail.fm> wrote:
>
>>Even though ains(...,...,2) reportedly can add a column to an existing
>>array, I don't quite see how to do it. Given an array dimensioned [3,2]
>>for
>>instance, what commands would I use to add a column so the resulting array
>>would have dimensions [3,3] and the contents of cols 1 & 2 would remain
>>intact?
>
> I have never found a way to make it work. I copy the array,
> redimension it, then copy the appropriate elements back.



Re: How to ains(xx,xx,2) a new column by Bernhard

Bernhard
Mon Aug 21 09:00:15 CDT 2006

Hi Lew,

> ...exactly my experience, too.
In older version, Foxpro internally treated an array like a one-dimensional
array (I think, this is still the way it does). The elements of a 2-dimensional
array are arranged, so that one row follows the other. If you re-dimension an
array, then the requested number of new elements are added at the end of this
internal one-dimensional array. Thus, if you add rows to a 2-dimensional array,
there is no problem, the newly added elements just make the new rows. But if you
add new columns, then the elements get new 2-dimensional indexes and the array
is messed up.

Example:
dimension: (3,3)
1 2 3
4 5 6
7 8 9
internal 1-dimensional arrangement:
1 2 3 4 5 6 7 8 9

new dimension: (4, 3), add new elements with 10, 11, 12
internally:
1 2 3 4 5 6 7 8 9 10 11 12
2-dimensions:
1 2 3
4 5 6
7 8 9
10 11 12

new dimension: (3, 4)
internally:
1 2 3 4 5 6 7 8 9 10 11 12
2-dimensions:
1 2 3 4
5 6 7 8
9 10 11 12
surely not what one expects

Regards
Bernhard Sander

Re: How to ains(xx,xx,2) a new column by Lew

Lew
Mon Aug 21 09:13:25 CDT 2006

I understand this, but it begs the question: what does the 2 as a last
parameter to ains() actually do? The docs say it'll add a column.
-Lew
"Bernhard Sander" <fuchs@no.spam> wrote in message
news:uWtkhoSxGHA.4484@TK2MSFTNGP02.phx.gbl...
> Hi Lew,
>
>> ...exactly my experience, too.
> In older version, Foxpro internally treated an array like a
> one-dimensional array (I think, this is still the way it does). The
> elements of a 2-dimensional array are arranged, so that one row follows
> the other. If you re-dimension an array, then the requested number of new
> elements are added at the end of this internal one-dimensional array.
> Thus, if you add rows to a 2-dimensional array, there is no problem, the
> newly added elements just make the new rows. But if you add new columns,
> then the elements get new 2-dimensional indexes and the array is messed
> up.
>
> Example:
> dimension: (3,3)
> 1 2 3
> 4 5 6
> 7 8 9
> internal 1-dimensional arrangement:
> 1 2 3 4 5 6 7 8 9
>
> new dimension: (4, 3), add new elements with 10, 11, 12
> internally:
> 1 2 3 4 5 6 7 8 9 10 11 12
> 2-dimensions:
> 1 2 3
> 4 5 6
> 7 8 9
> 10 11 12
>
> new dimension: (3, 4)
> internally:
> 1 2 3 4 5 6 7 8 9 10 11 12
> 2-dimensions:
> 1 2 3 4
> 5 6 7 8
> 9 10 11 12
> surely not what one expects
>
> Regards
> Bernhard Sander



Re: How to ains(xx,xx,2) a new column by Bernhard

Bernhard
Mon Aug 21 09:34:53 CDT 2006

Hi Lew,

> I understand this, but it begs the question: what does the 2 as a last
> parameter to ains() actually do? The docs say it'll add a column.
The docs (VFP9) tell, it inserts a column <g>.
Nether AIns nor ADel change the dimension. They shift the rest of the array.
AIns shifts from nElementNumber (the second parameter) to the end of the array,
the last elements (the row, or with 2 as the last parameter the column) get
lost. Then the elements of row or column nElementNumber are initialised with .F.
ADel shifts the remaining elements from the end to nElementNumber. At the end,
the elements are initialised with .F.
In one dimensional arrays, it is quiet obvious, what happens.
In 2 dimensional arrays, without the third parameter, the shift is by row.
With 2 as the third parameter, the shift is by column.

Regards
Bernhard Sander

Re: How to ains(xx,xx,2) a new column by Lew

Lew
Mon Aug 21 10:22:26 CDT 2006

...so it'd be more accurate to say that ains()/col copies columns just as
ains()/row copies things down & stuff is lost if there isn't enough room in
the first place.
"Bernhard Sander" <fuchs@no.spam> wrote in message
news:unJ%2347SxGHA.4944@TK2MSFTNGP02.phx.gbl...
> Hi Lew,
>
>> I understand this, but it begs the question: what does the 2 as a last
>> parameter to ains() actually do? The docs say it'll add a column.
> The docs (VFP9) tell, it inserts a column <g>.
> Nether AIns nor ADel change the dimension. They shift the rest of the
> array.
> AIns shifts from nElementNumber (the second parameter) to the end of the
> array, the last elements (the row, or with 2 as the last parameter the
> column) get lost. Then the elements of row or column nElementNumber are
> initialised with .F.
> ADel shifts the remaining elements from the end to nElementNumber. At the
> end, the elements are initialised with .F.
> In one dimensional arrays, it is quiet obvious, what happens.
> In 2 dimensional arrays, without the third parameter, the shift is by row.
> With 2 as the third parameter, the shift is by column.
>
> Regards
> Bernhard Sander



Re: How to ains(xx,xx,2) a new column by Roger

Roger
Mon Aug 21 10:50:26 CDT 2006

Lew Schwartz wrote:
> ...so it'd be more accurate to say that ains()/col copies columns
> just as ains()/row copies things down & stuff is lost if there isn't
> enough room in the first place.

I think it would be more accurate to RTFM ;o)

From VFP Help ...
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.

-Roger


> "Bernhard Sander" <fuchs@no.spam> wrote in message
> news:unJ%2347SxGHA.4944@TK2MSFTNGP02.phx.gbl...
>> Hi Lew,
>>
>>> I understand this, but it begs the question: what does the 2 as a
>>> last parameter to ains() actually do? The docs say it'll add a
>>> column.
>> The docs (VFP9) tell, it inserts a column <g>.
>> Nether AIns nor ADel change the dimension. They shift the rest of the
>> array.
>> AIns shifts from nElementNumber (the second parameter) to the end of
>> the array, the last elements (the row, or with 2 as the last
>> parameter the column) get lost. Then the elements of row or column
>> nElementNumber are initialised with .F.
>> ADel shifts the remaining elements from the end to nElementNumber.
>> At the end, the elements are initialised with .F.
>> In one dimensional arrays, it is quiet obvious, what happens.
>> In 2 dimensional arrays, without the third parameter, the shift is
>> by row. With 2 as the third parameter, the shift is by column.
>>
>> Regards
>> Bernhard Sander



Re: How to ains(xx,xx,2) a new column by Dan

Dan
Mon Aug 21 11:04:30 CDT 2006

In otherwords, it behaves exactly the same way. <g>

Many years ago when we first got ADEL() in the language, a developer working
with me fumed and fumed that it didn't work. "It says RIGHT HERE (in the
help file) that it deletes an array element!" He banged his head on it for a
good two hours.

After he left work that day, I printed that help topic and hilited the NEXT
sentence that says "ADEL() does not redimension the array" and left it on
his desk.

Perhaps the help should talk about ins/del of elements or values rather than
rows or columns.

Dan

Lew Schwartz wrote:
> ...so it'd be more accurate to say that ains()/col copies columns
> just as ains()/row copies things down & stuff is lost if there isn't
> enough room in the first place.
> "Bernhard Sander" <fuchs@no.spam> wrote in message
> news:unJ%2347SxGHA.4944@TK2MSFTNGP02.phx.gbl...
>> Hi Lew,
>>
>>> I understand this, but it begs the question: what does the 2 as a
>>> last parameter to ains() actually do? The docs say it'll add a
>>> column.
>> The docs (VFP9) tell, it inserts a column <g>.
>> Nether AIns nor ADel change the dimension. They shift the rest of the
>> array.
>> AIns shifts from nElementNumber (the second parameter) to the end of
>> the array, the last elements (the row, or with 2 as the last
>> parameter the column) get lost. Then the elements of row or column
>> nElementNumber are initialised with .F.
>> ADel shifts the remaining elements from the end to nElementNumber.
>> At the end, the elements are initialised with .F.
>> In one dimensional arrays, it is quiet obvious, what happens.
>> In 2 dimensional arrays, without the third parameter, the shift is
>> by row. With 2 as the third parameter, the shift is by column.
>>
>> Regards
>> Bernhard Sander



Re: How to ains(xx,xx,2) a new column by Jack

Jack
Mon Aug 21 12:02:23 CDT 2006

On Tue, 22 Aug 2006 01:20:26 +0930, "Roger Ansell"
<notmyreal@emailaddress.com> wrote:

>Lew Schwartz wrote:
>> ...so it'd be more accurate to say that ains()/col copies columns
>> just as ains()/row copies things down & stuff is lost if there isn't
>> enough room in the first place.
>
>I think it would be more accurate to RTFM ;o)
>
>From VFP Help ...
>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.
>
>-Roger

Yes it says that, but the result, as far as I can tell, is that it is
impossible to insert a column in a two-dimensional array using AINS
without losing data. If that's true, then it seems like the FM should
say so.