[AccessD] [EXTERNAL] Re: Parameter (argument) order
Stuart McLachlan
stuart at lexacorp.com.pg
Fri Feb 17 15:32:23 CST 2023
You CAN'T pass as array BYVAL in VBA. If you try
Function Fillarr(byval arr() As String, idx As Long, sVal As String) As Long
you will get an error:
Compile error:
Array argument must be ByRef
Rocky's reference was under VB .Net. For .Net:
There are two types in .NET, value types and reference types.
Value types are the basic types, such as int, long, double, etc. This includes
structures and enums. As you would guess, value types are passed by value by
default.
Reference types are objects, which is pretty much everything else not mentioned
above. This includes arrays and strings. As you would guess, reference types are
passed by reference by default.
On 18 Feb 2023 at 7:17, Stuart McLachlan wrote:
> That articleis incorrect for VBA when it says:
> "The default in Visual Basic is to pass arguments by value. "
>
...
> > Can't you use byref in the function for the parameters?
> >
> > Passing Arguments by Value and by Reference - Visual Basic |
> > Microsoft Learn
> > <https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-g
> > ui
> > de/language-features/procedures/passing-arguments-by-value-and-by-re
> > fe rence>
> >
> > r
> >
> > On Thu, Feb 16, 2023 at 10:24 PM Arthur Fuller
> > <fuller.artful at gmail.com> wrote:
> >
> > > Thanks for trying, Stuart. You know that I love your mind and
> > > intellect. But apparently I am still failing to pose my question
> > > properly. Let me try once more. I want to pass two arrays to a
> > > function, and then do whatever I want with them. One simple
> > > possibility is to compare them. Another is to concatenate them and
> > > return the result. A third is to "subtract" them and return the
> > > difference as a tiny array. Another is to perform a
> > > matrix-multiplication on them, and return that result.
> > >
> > > the template is simple:
> > > Function arrManipulate(a1,a2) as <whatever> 'not sure how to
> > > declare the args; as Variant? Do Somestuff with a1 and a2 '
> > > they are both arrays Return SomeResult End Function
> > >
> > > Maybe I'm missing something in VBA, but so far I can't seem to get
> > > from here to there. It's easy in C and C++, but I have not yet
> > > arrived at the equivalent method in VBA.
> > >
> > > On Fri, Feb 17, 2023 at 1:08 AM Stuart McLachlan
> > > <stuart at lexacorp.com.pg> wrote:
> > >
> > > > On 17 Feb 2023 at 5:07, Shane Groff via AccessD wrote:
> > > >
> > > > > https://learn.microsoft.com/en-us/office/vba/language/concepts
> > > > > /g etting -started/understanding-parameter-arrays
> > > > >
> > > > > A ParamArray is not for passing an array as an argument, it is
> > > > > for allowing you to pass a dynamic number of arguments as an
> > > > > array:
> > > > >
> > > > > If you declare:
> > > > > Function CalcSum(ParamArray args() as Variant) As Double
> > > > >
> > > > > You can call it like so:
> > > > >
> > > > > x = CalcSum(34, 47, 99, 12)
> > > > > or
> > > > > x = CalcSum(1, 1)
> > > > >
> > > > > and it can add all the arguments together (it receives all the
> > > > > arguments as a single array).
> > > > >
> > > > > It must be the last argument in the declaration, since all the
> > > > > arguments at the end of the caller will be 'consumed' to
> > > > > create the array, so there can't be any additional arguments.
> > > > >
> > > >
> > > > Another way to pass a series of arguments as an array :)
> > > > Function PassArray() As Long
> > > > Dim v As Variant
> > > > v = Array("Some text", 2, 3)
> > > > UseArray v
> > > > End Function
> > > >
> > > > Function UseArray(v As Variant) As Long
> > > > Debug.Print Mid$(v(0), v(1), v(2))
> > > > End Function
> > > > --
> > > > 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
> >
>
>
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>
More information about the AccessD
mailing list