[AccessD] Problems with Arrays

John Colby jwcolby at gmail.com
Fri Jan 20 04:14:43 CST 2023


Well, my apologies.  I was searching on VBA and vb.net is what I got.  I am
reasonably sure that the same holds true for VBA, i.e. all objects are
passed by reference and that means that a pointer is passed.

To reiterate, any time you assign an object to a variable, VBA grabs a
pointer to that object and assigns that to the variable you are setting.
If you think about it, that makes sense.  If I dimension a recordset *variable
*(an object) and then SET that variable, it is not a copy of the recordset
that I am setting the variable to.  Same thing with setting a form
variable, or a combo variable.

The point (pun intended) is that pointers are used everywhere in VBA, it is
just that they are not in your face as in other languages.

On Thu, Jan 19, 2023 at 9:04 AM Arthur Fuller <fuller.artful at gmail.com>
wrote:

> Hi John,
>
> I read the page you cited, and copied the code that demonstrates byVal v.
> ByRef. This code might work in VB but Access VBA sure doesn't like it.
> Seems the problem is in the declarations, such as:
>
>     Dim lowRate = highRate * 0.6
>
>     Dim initialDebt = 4999.99
>     ' Make a copy of the original value of the debt.
>     Dim debtWithInterest = initialDebt
>
> All three Dim statements are flagged in red-underline. This does not
> surprise me since I've never seen variables declared that way; rather, they
> are declared and assigned values on separate lines.
>
> Am I missing something? Wouldn't be the first time.
>
> On Wed, Jan 18, 2023 at 4:43 PM John Colby <jwcolby at gmail.com> wrote:
>
> > I was under the impression that any time you pass any parameter ByRef you
> > were passing in a pointer.
> >
> >
> >
> https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/passing-arguments-by-value-and-by-reference
> >
> > The third para states:
> >
> > For reference types, only the pointer to the data is copied (four bytes
> on
> > 32-bit platforms, eight bytes on 64-bit platforms). Therefore, you can
> pass
> > arguments of type String or Object by value without harming performance.
> >
> > Furthermore AFAIK objects in VBA can *only* be passed ByRef.  For example
> > passing a text box into a function.
> >
> > On Wed, Jan 18, 2023 at 1:13 PM Arthur Fuller <fuller.artful at gmail.com>
> > wrote:
> >
> > > Are we talking VBA or another language? I seldom use the word "pointer"
> > in
> > > discussions of VBA, because VBA doesn't implement pointers, at least
> not
> > > that I know of (as in C and C++). So what exactly do you mean? I am
> very
> > > curious to learn this technique.
> > >
> > > On Tue, Jan 17, 2023 at 4:35 PM Stuart McLachlan <
> stuart at lexacorp.com.pg
> > >
> > > wrote:
> > >
> > > > On 17 Jan 2023 at 14:34, Arthur Fuller wrote:
> > > >
> > > > > One question, before I load my revolver and do something stupid...
> > Can
> > > > > a function return an array? If so, I can work with that and get
> where
> > > > > I need to go.
> > > > >
> > > > Not directly, but:
> > > > A function can return a Variant and a Variant can contain an array
> > > > Or a function can accept or return a pointer to an array
> > > >
> > > > --
> > > > 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
> > >
> >
> >
> > --
> > John W. Colby
> > Colby Consulting
> > --
> > 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
>


-- 
John W. Colby
Colby Consulting


More information about the AccessD mailing list