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 ---
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 trukker41@gmail.com 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]
On 21/04/2016 11:43, Laurie Alvey 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
Never had an occasion to swap variables. Under what sort of situation is this useful?
Thanks,
Peter
This communication is intended for the person or organisation to whom it is addressed. The contents are confidential and may be protected in law. Unauthorised use, copying or disclosure of any of it may be unlawful. If you have received this message in error, please notify us immediately by telephone or email.
www.whisperingsmith.com
Whispering Smith Ltd Head Office:61 Great Ducie Street, Manchester M3 1RR. Tel:0161 831 3700 Fax:0161 831 3715
London Office:17-19 Foley Street, London W1W 6DW Tel:0207 299 7960
I don't think I've swapped variables since writing bubble sorts 40 years ago.
Mike
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Peter Cushing Sent: Thursday, April 21, 2016 7:47 AM To: profoxtech@leafe.com Subject: Re: Swap two variables
On 21/04/2016 11:43, Laurie Alvey 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
Never had an occasion to swap variables. Under what sort of situation is this useful?
Thanks,
Peter
This communication is intended for the person or organisation to whom it is addressed. The contents are confidential and may be protected in law. Unauthorised use, copying or disclosure of any of it may be unlawful. If you have received this message in error, please notify us immediately by telephone or email.
www.whisperingsmith.com
Whispering Smith Ltd Head Office:61 Great Ducie Street, Manchester M3 1RR. Tel:0161 831 3700 Fax:0161 831 3715
London Office:17-19 Foley Street, London W1W 6DW Tel:0207 299 7960
[excessive quoting removed by server]
I changed the PROCEDURE to a FUNCTION. Same error.
Laurie
On 22 April 2016 at 02:26, mbsoftwaresolutions@mbsoftwaresolutions.com wrote:
On 2016-04-21 10:54, Michael Glassman wrote:
I don't think I've swapped variables since writing bubble sorts 40 years ago.
+1 back in the late 80s first learning to program on a TRS-80 (BASIC) and then Apple IIe (Pascal).
[excessive quoting removed by server]
If you ever do any work in linear algebra, swapping array elements is important in pivoting and linear programming (simplex) methods.
Laurie
On 22 April 2016 at 09:59, Laurie Alvey trukker41@gmail.com wrote:
I changed the PROCEDURE to a FUNCTION. Same error.
Laurie
On 22 April 2016 at 02:26, mbsoftwaresolutions@mbsoftwaresolutions.com wrote:
On 2016-04-21 10:54, Michael Glassman wrote:
I don't think I've swapped variables since writing bubble sorts 40 years ago.
+1 back in the late 80s first learning to program on a TRS-80 (BASIC) and then Apple IIe (Pascal).
[excessive quoting removed by server]
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.
Hi Laurie,
The Help file, on the "Passing Data to Parameters" section, says:
"Note: When passing entire arrays to parameters, you must pass them by reference. If you do not pass arrays by reference, only the first element is passed. Therefore, individual array elements are always passed by value"
This was the functionallity from dBase times, and changing between procedures and functions does not make any difference.
Regards.-
2016-04-22 10:59 GMT+02:00 Laurie Alvey trukker41@gmail.com:
I changed the PROCEDURE to a FUNCTION. Same error.
Laurie
--- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html ---
ditto - but nearly 50 years ago - and back then I used the triple XOR method (IBM 360 macro-assember) <s>
On 21/04/2016 20:24, Michael Glassman wrote:
I don't think I've swapped variables since writing bubble sorts 40 years ago.
Mike
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Peter Cushing Sent: Thursday, April 21, 2016 7:47 AM To: profoxtech@leafe.com Subject: Re: Swap two variables
On 21/04/2016 11:43, Laurie Alvey 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
Never had an occasion to swap variables. Under what sort of situation is this useful?
Thanks,
Peter
This communication is intended for the person or organisation to whom it is addressed. The contents are confidential and may be protected in law. Unauthorised use, copying or disclosure of any of it may be unlawful. If you have received this message in error, please notify us immediately by telephone or email.
www.whisperingsmith.com
Whispering Smith Ltd Head Office:61 Great Ducie Street, Manchester M3 1RR. Tel:0161 831 3700 Fax:0161 831 3715
London Office:17-19 Foley Street, London W1W 6DW Tel:0207 299 7960
[excessive quoting removed by server]
The triple XOR method will only work with integers in VFP. Don't know about other languages.
Laurie
On 22 April 2016 at 22:21, AndyHC andy@hawthorncottage.com wrote:
ditto - but nearly 50 years ago - and back then I used the triple XOR method (IBM 360 macro-assember) <s>
On 21/04/2016 20:24, Michael Glassman wrote:
I don't think I've swapped variables since writing bubble sorts 40 years ago.
Mike
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Peter Cushing Sent: Thursday, April 21, 2016 7:47 AM To: profoxtech@leafe.com Subject: Re: Swap two variables
On 21/04/2016 11:43, Laurie Alvey 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
Never had an occasion to swap variables. Under what sort of situation is
this useful?
Thanks,
Peter
This communication is intended for the person or organisation to whom it is addressed. The contents are confidential and may be protected in law. Unauthorised use, copying or disclosure of any of it may be unlawful. If you have received this message in error, please notify us immediately by telephone or email.
www.whisperingsmith.com
Whispering Smith Ltd Head Office:61 Great Ducie Street, Manchester M3 1RR. Tel:0161 831 3700 Fax:0161 831 3715
London Office:17-19 Foley Street, London W1W 6DW Tel:0207 299 7960
[excessive quoting removed by server]
At 07:54 2016-04-21, "Michael Glassman" MHGlassman@PioneerDrama.com wrote:
I don't think I've swapped variables since writing bubble sorts 40 years ago.
I do occasionally.
On report parameter forms where I have a date range, if the dates are in the wrong order, I simply swap the dates rather than giving an error message.
I have another program where the table can be viewed in forward or reverse order. I have a swap in there.
I also occasionally use call-by-reference. Again, not often, but when you need it, it is good to have.
[snip]
Sincerely,
Gene Wirchenko
On Thu, Apr 21, 2016 at 6:43 AM, Laurie Alvey trukker41@gmail.com wrote:
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.
"Function argument value, type, or count is invalid"
And why do you think that is?
I suspect it's because you can't pass a single array element by reference, only the array. Passing by reference needs reference toa *variable* like liCustomerPK. An array element is not a variable.
Hi Ted,
That's my conclusion too.
Laurie
On 22 April 2016 at 12:17, Ted Roche tedroche@gmail.com wrote:
On Thu, Apr 21, 2016 at 6:43 AM, Laurie Alvey trukker41@gmail.com wrote:
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.
"Function argument value, type, or count is invalid"
And why do you think that is?
I suspect it's because you can't pass a single array element by reference, only the array. Passing by reference needs reference toa *variable* like liCustomerPK. An array element is not a variable.
[excessive quoting removed by server]