From: M on
Hello:

I didn't get a chance to test this yet and haven't found a clear answer online.

If I have 3 parameters, and I want them all to be passed by value, do I need to specify ByVal 3 separate times like this: Sub subTest(ByVal strParam1, ByVal strParam2, ByVal strParam3), or can I specify ByVal once and have it apply to all parameters, like this: Sub subTest(ByVal strParam1, strParam2, strParam3)?

Thank you.

--
Regards,
M
MCTS, MCSA
http://SysAdmin-E.com
From: Tom Lavedas on
On May 27, 4:34 pm, "M" <m...(a)nowhere.com> wrote:
> Hello:
>
> I didn't get a chance to test this yet and haven't found a clear answer online.
>
> If I have 3 parameters, and I want them all to be passed by value, do I need to specify ByVal 3 separate times like this: Sub subTest(ByVal strParam1, ByVal strParam2, ByVal strParam3), or can I specify ByVal once and have it apply to all parameters, like this: Sub subTest(ByVal strParam1, strParam2, strParam3)?
>
> Thank you.
>
> --
> Regards,
> M
> MCTS, MCSAhttp://SysAdmin-E.com

Three times.
_____________________
Tom Lavedas
From: Al Dunbar on


"Tom Lavedas" <tglbatch(a)verizon.net> wrote in message
news:46213a90-9ee8-4fdc-bb9f-57d3dd9925e3(a)z17g2000vbd.googlegroups.com...
> On May 27, 4:34 pm, "M" <m...(a)nowhere.com> wrote:
>> Hello:
>>
>> I didn't get a chance to test this yet and haven't found a clear answer
>> online.
>>
>> If I have 3 parameters, and I want them all to be passed by value, do I
>> need to specify ByVal 3 separate times like this: Sub subTest(ByVal
>> strParam1, ByVal strParam2, ByVal strParam3), or can I specify ByVal once
>> and have it apply to all parameters, like this: Sub subTest(ByVal
>> strParam1, strParam2, strParam3)?
>>
>> Thank you.
>>
>> --
>> Regards,
>> M
>> MCTS, MCSAhttp://SysAdmin-E.com
>
> Three times.

Agreed. Also, it appears to be fairly clear here:

http://msdn.microsoft.com/en-us/library/x7hbf8fa(VS.85).aspx

where it states that:

The arglist argument has the following syntax and parts:

[ByVal | ByRef] varname[( )]

Arguments
--------------------------------------------------------------------------------

ByVal
Indicates that the argument is passed by value.

ByRef
Indicates that the argument is passed by reference. If ByVal and ByRef
are omitted, the default is ByRef.

If these keywords were to apply to subsequent parameters, the syntax would
have to be different, and so would the explanation, for example, "the
argument", would be given as "the argument plus all following unqualified
arguments"

/Al


From: Todd Vargo on
Al Dunbar wrote:
> Tom Lavedas wrote:
>> On May 27, 4:34 pm, "M" <m...(a)nowhere.com> wrote:
>>> Hello:
>>>
>>> I didn't get a chance to test this yet and haven't found a clear answer
>>> online.
>>>
>>> If I have 3 parameters, and I want them all to be passed by value, do I
>>> need to specify ByVal 3 separate times like this: Sub subTest(ByVal
>>> strParam1, ByVal strParam2, ByVal strParam3), or can I specify ByVal
>>> once and have it apply to all parameters, like this: Sub subTest(ByVal
>>> strParam1, strParam2, strParam3)?
>>>
>>> Thank you.
>>>
>>> --
>>> Regards,
>>> M
>>> MCTS, MCSAhttp://SysAdmin-E.com
>>
>> Three times.
>
> Agreed. Also, it appears to be fairly clear here:
>
> http://msdn.microsoft.com/en-us/library/x7hbf8fa(VS.85).aspx
>
> where it states that:
>
> The arglist argument has the following syntax and parts:
>
> [ByVal | ByRef] varname[( )]
>
> Arguments
> --------------------------------------------------------------------------------
>
> ByVal
> Indicates that the argument is passed by value.
>
> ByRef
> Indicates that the argument is passed by reference. If ByVal and ByRef
> are omitted, the default is ByRef.
>
> If these keywords were to apply to subsequent parameters, the syntax would
> have to be different, and so would the explanation, for example, "the
> argument", would be given as "the argument plus all following unqualified
> arguments"

Of course, OP could have answered their own question with a simple test.

var1 = "ByVal"
var2 = "ByVal"
test var1, var2
msgbox "var1=" & var1 & vbNewline & "var2=" & var2

sub test(ByVal var1, var2)
var1 = "ByRef"
var2 = "ByRef"
end sub

--
Todd Vargo

(Post questions to group only. Remove "z" to email personal messages)

From: Al Dunbar on


"Todd Vargo" <tlvargo(a)sbcglobal.netz> wrote in message
news:#APl8nh$KHA.5848(a)TK2MSFTNGP06.phx.gbl...
> Al Dunbar wrote:
>> Tom Lavedas wrote:
>>> On May 27, 4:34 pm, "M" <m...(a)nowhere.com> wrote:
>>>> Hello:
>>>>
>>>> I didn't get a chance to test this yet and haven't found a clear answer
>>>> online.
>>>>
>>>> If I have 3 parameters, and I want them all to be passed by value, do I
>>>> need to specify ByVal 3 separate times like this: Sub subTest(ByVal
>>>> strParam1, ByVal strParam2, ByVal strParam3), or can I specify ByVal
>>>> once and have it apply to all parameters, like this: Sub subTest(ByVal
>>>> strParam1, strParam2, strParam3)?
>>>>
>>>> Thank you.
>>>>
>>>> --
>>>> Regards,
>>>> M
>>>> MCTS, MCSAhttp://SysAdmin-E.com
>>>
>>> Three times.
>>
>> Agreed. Also, it appears to be fairly clear here:
>>
>> http://msdn.microsoft.com/en-us/library/x7hbf8fa(VS.85).aspx
>>
>> where it states that:
>>
>> The arglist argument has the following syntax and parts:
>>
>> [ByVal | ByRef] varname[( )]
>>
>> Arguments
>> --------------------------------------------------------------------------------
>>
>> ByVal
>> Indicates that the argument is passed by value.
>>
>> ByRef
>> Indicates that the argument is passed by reference. If ByVal and ByRef
>> are omitted, the default is ByRef.
>>
>> If these keywords were to apply to subsequent parameters, the syntax
>> would have to be different, and so would the explanation, for example,
>> "the argument", would be given as "the argument plus all following
>> unqualified arguments"
>
> Of course, OP could have answered their own question with a simple test.

Granted - but he said he didn't have time to do that.

Funny, though, that he (apparently) did have time for an unsuccessful look
"for a clear answer online"!

So he got a few answers of "three times" from us. I wonder what his
conclusion would have been had someone given a dissenting opinion.

/Al

> var1 = "ByVal"
> var2 = "ByVal"
> test var1, var2
> msgbox "var1=" & var1 & vbNewline & "var2=" & var2
>
> sub test(ByVal var1, var2)
> var1 = "ByRef"
> var2 = "ByRef"
> end sub
>
> --
> Todd Vargo
>
> (Post questions to group only. Remove "z" to email personal messages)