Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Xbase Fox > Re: VFP Array E...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 830 of 861
Post > Topic >>

Re: VFP Array Element Handling Gotcha

by Rush Strong <rpstrong@[EMAIL PROTECTED] > Feb 13, 2008 at 01:44 AM

Gene Wirchenko wrote:
>      I just got bit in a minor way with the way that VFP handles array
> elements.  Consider the following code:
>
>    local twod(10,2)
>    for i=1 to 10
>       for j=1 to 2
>          twod(i,j)=10*i+j
>          endfor
>       endfor
>    ? twod(4,3)
>
>      Note the array dimensions and the reference.  The reference is
> treated as being the third element starting in row 4 with VFP not
> checking against the declared dimension.  The reference is treated as
> referring to twod(5,1), not as being an error.
>
>      The docs do say that 2-D arrays can be accessed as 1-D.  The
> implementation appears to be more general than that.  Forewarned is
> forearmed and all that.
>
>   

The docs would be more accurate to say that 1-D arrays can be accessed 
as 2-D, because 1-D is all that Fox can handle.  That is, every array is 
one dimensional.  Declaring twod(10,2) creates the same 20 element array 
as twod(20) [or as twod(5,4)].  The 2-D conceit is a logical 2-D 
addressing scheme, but does not affect the actual array structure.  It 
appears that Fox locates twod[4,3] by locating the element corresponding 
to the start of the logical fourth row by multiplying the declared 
number of columns (2) times 4 - which is element number 7 - and then 
moves the pointer by two more elements, to element number 9.  This, as 
you noted, is the result of ASUBSCRIPT(9).

The 1-D structure also explains the behavior of re-dimensioning an 
array.  If aFoo(3, 3) is:

    1  2  3
    4  5  6
    7  8  9

DIMENSION aFoo(2, 2) will result in:

    1  2
    3  4

as opposed to:

    1  2
    4  5

As you said, forewarned is forearmed.

 - Rush
 




 3 Posts in Topic:
VFP Array Element Handling Gotcha
Gene Wirchenko <genew@  2008-02-12 16:20:41 
Re: VFP Array Element Handling Gotcha
Rush Strong <rpstrong@  2008-02-13 01:44:41 
Re: VFP Array Element Handling Gotcha
Rush Strong <rpstrong@  2008-02-13 01:49:27 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 23:27:11 CDT 2008.