all groups > vb.net upgrade > october 2003 >
You're in the

vb.net upgrade

group:

ByRef ParamArray alternative


ByRef ParamArray alternative DonKolafa
10/27/2003 11:26:46 AM
vb.net upgrade:
Is anyone aware of a reasonable syntax or procedural substitute for the
'ByRef ParamArray' of VB6. It may seem a trivial change to 'ByVal
ParamArray' in VB.NET, but if you have a very large number of parameters,
that you wish to change....you are up a creek.

My specific problem is emulating a Business Basic READ statement where the
calling program simply supplies a list of variables, and the physical file
read routine parses them into the various variables. My VB6 version of this
product works because of the ByRef ParamArray:

bbREAD 7,bbIO("KEY=" & K$,"ERR=A05511"), A$, B$, Y, Z, Null, Null, N

is properly interpreted by declaring

Public Sub bbREAD(Unit as Integer, IOParms as String, ParamArray Parms() as
Variant)

Don Kolafa
Don@Kolafa.com
www.Kolafa.com

Re: ByRef ParamArray alternative Jay B. Harlow [MVP - Outlook]
10/27/2003 2:45:28 PM
Don,
Unfortunately there is no real substitute. I had a discussion with someone 9
months to a year ago about this. I don't remember coming up with a viable
alternative (him or I).

I would suggest an overloaded bbREAD procedure, however I suspect that is
going to get very complicated very quickly for what you are attempting.

I not sure how many hits you would get if you attempted to search
http://groups.google.com for ParamArray, maybe you could find the thread
that I referenced. My concern is it will be like finding a needle in a hay
stack.

Hope this helps
Jay

[quoted text, click to view]

Re: ByRef ParamArray alternative Jay B. Harlow [MVP - Outlook]
10/31/2003 6:48:11 PM
Alexandre,
You're not really using the ParamArray in that case, I would simply pass the
array of object! and not bother with the ParamArray.

[quoted text, click to view]

The intent of ParamArray is such that you do not need to create the array
yourself, if you look at the assembly using ILDASM.EXE for ParamArray
parameters, you will see that the it is effectively the code you gave.

You code also demonstrates that you can call ParamArray methods with just an
array, and it is passed as 'expected'.

Hope this helps
Jay

[quoted text, click to view]

RE: ByRef ParamArray alternative amoura NO[at]SPAM online.microsoft.com
10/31/2003 10:15:23 PM
There is no easy workaround that I know of - however, you can still use a
paramarray and obtain the values back if you use the following trick:

Module Module1

Sub Main()
Dim i As Integer = 4
Dim s As String = "123"
Dim obj() As Object = New Object() {i, s}
foo(obj)
i = obj(0)
s = obj(1)

Console.WriteLine(i)
Console.WriteLine(s)
End Sub

Sub foo(ByVal ParamArray arg() As Object)
arg(0) = 1
arg(1) = "abc"
End Sub

End Module

this code calls a method taking a paramarray by creating the array in
advance - the method changes the array member's values, and it recovers
them to the original variables - this code prints 1 then "abc".

Hope that helps.

--------------------
[quoted text, click to view]
cpmsftngxa06.phx.gbl!cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP12.
phx.gbl
[quoted text, click to view]
AddThis Social Bookmark Button