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

Rolf-Werner Eilert rwe-sse at osnanet.de
Fri Oct 9 10:40:09 CEST 2020


Am 09.10.20 um 10:09 schrieb Benoît Minisini:
> Le 09/10/2020 à 10:07, Benoît Minisini a écrit :
>> 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,
>>
> 
> By the way your request is right in a way. An array Swap() method would 
> ba a little bit faster than the Swap instruction.
> 

Aaah thanks for the quick answer! I now remember I once used it. And 
this way, it is more flexible, as one can swap items from two different 
arrays.

Thanks to both of you!

Rolf



More information about the User mailing list