You were using the procedure instead of a function Swap(@a[1], @a[2])
 inside of PROCEDURE Swap(v1, v2)

Compiler should have barfed that one up for you.



On Thu, Apr 21, 2016 at 5:43 AM, Laurie Alvey <[email protected]> wrote:

> I'm sure we're all familiar with the standard way to swap two variables:
>
> LOCAL p, q
> p = 1
> q = 2
> Swap(@p, @q) && pass by reference
>
> PROCEDURE Swap(v1, v2)
> LOCAL dum
> dum = v1
> v1 = v2
> v2 = dum
> ENDPROC
>
> Using this technique to swap two array elements doesn't work. If you try
> this:
>
> LOCAL  ARRAY a[2]
> a[1] = 1
> a[2] = 2
> Swap(@a[1], @a[2])
>
> you'll get Error 11.
>
> Instead, this will work:
>
> LOCAL  ARRAY a[2]
> a[1] = 1
> a[2] = 2
> ASwap(@a, 1, 2)
>
> PROCEDURE ASwap(p, i1, i2)
> *!* i1 and i2 are the ELEMENT numbers to be swapped
> LOCAL dum
> dum = p[i1]
> p[i1] = p[i2]
> p[i2] = dum
> ENDPROC
>
> Laurie
>
>
> --- StripMime Report -- processed MIME parts ---
> multipart/alternative
>   text/plain (text body -- kept)
>   text/html
> ---
>
[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: http://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/cajidmy+9dfvidp_khzuwn96wcmhfhmgh-hsnmgrmv89g1kd...@mail.gmail.com
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to