[AccessD] Swap two elements in an array
Arthur Fuller
fuller.artful at gmail.com
Thu Aug 18 11:16:42 CDT 2022
Thanks, Stuart.
After sending my message, I rolled my own, using exactly the same technique
as you -- couldn't think of a way around the temp variable.
On Thu, Aug 18, 2022 at 9:41 AM Stuart McLachlan <stuart at lexacorp.com.pg>
wrote:
> Since VBA doesn't have a SWAP function, you have to do it with a temporary
> variable
> Assuming it's a one dimensional array, something like:
>
> Temp = Arr(2) : Arr(2) = Arr(4) : Arr(4) = Temp
> If you define Temp as a Variant, you can use it with any type of array.
>
> If it's a multi-dimensional array, you have to sway each dimension:
> Temp = Arr(1,2) : Arr(1,2) = Arr(1,4) : Arr(1,4) = Temp
> Temp = Arr(2,2) : Arr(2,2) = Arr(2,4) : Arr(2,4) = Temp
> Temp = Arr(3,2) : Arr(3,2) = Arr(3,4) : Arr(3,4) = Temp
> ...
>
>
> On 18 Aug 2022 at 8:35, Arthur Fuller wrote:
>
> > What is the best way to swap two elements in an array? Typically they
> > are adjacent but ideally I want a method that can swap any two
> > elements.
> >
> > --
> > Arthur
> > --
> > AccessD mailing list
> > AccessD at databaseadvisors.com
> > https://databaseadvisors.com/mailman/listinfo/accessd
> > Website: http://www.databaseadvisors.com
> >
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
--
Arthur
More information about the AccessD
mailing list