[Gambas-user] Idea for arrays: .SWAP function

Benoît Minisini g4mba5 at gmail.com
Fri Oct 9 10:07:11 CEST 2020


Le 09/10/2020 à 09:55, Rolf-Werner Eilert a écrit :
> Hi Benoit and all,
> 
> Just had this one in a current project. To enable the user to push an 
> entry in a list one up or down, I have to swap the related values in 
> several arrays. There seems to be no swap function, so I have to write 3 
> lines of codes for it, like this:
> 
>   t$ = klName[po]
>   klName[po] = klName[po + 1]
>   klName[po + 1] = t$
> 
> I have to use these 3 lines for each array. How much easier it would be 
> if I could use a function like for this:
> 
> klName.Swap(po, po+1)
> 
> This would also make sense in ListBox etc.
> 
> I think this would enhance code and readability a lot.
> 
> Regards
> Rolf
> 

Do the following:

Swap klName[po], klName[po + 1]

It compiles into what you wrote, but using a stack slot instead of a 
local variable.

Regards,

-- 
Benoît Minisini


More information about the User mailing list