[AccessD] Swap two elements in an array

Arthur Fuller fuller.artful at gmail.com
Fri Aug 19 18:17:02 CDT 2022


Jim,
That  happens automatically if the array is passed, along with the element
numbers

On Fri, Aug 19, 2022 at 1:16 PM James Button via AccessD <
accessd at databaseadvisors.com> wrote:

> It may be a somewhat low process for items in a large array, depending on
> the
> need, or not for the array handling to create a new version of the array
> and
> copy everything from the old instance.
>
> I'll leave you do check if that applies to the array you have.
>
> If that does cause slow processing, maybe have an additional array with the
> replacement values, and in that including a key value indicating which
> element
> of the large base array the new entry is to apply for.
>
> Also - if anyone has a definite knowledge of the current memory management
> associated with arrays, could they post a summary to update my memory!
>
> JimB.
>
>
>
> -----Original Message-----
> From: AccessD
> <accessd-bounces+jamesbutton=blueyonder.co.uk at databaseadvisors.com> On
> Behalf Of
> Arthur Fuller
> Sent: Thursday, August 18, 2022 5:17 PM
> To: Access Developers discussion and problem solving
> <accessd at databaseadvisors.com>
> Subject: Re: [AccessD] Swap two elements in an array
>
> 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
> --
> 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