Re: ByVal for multiple parameters

T

Tom Lavedas

On May 27, 4:34 pm, "M" <[email protected]> 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
 

My Computer

A

Al Dunbar

"Tom Lavedas" <[email protected]> wrote in message
news:[email protected]

> On May 27, 4:34 pm, "M" <[email protected]> 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
 

My Computer

T

Todd Vargo

Al Dunbar wrote:

> Tom Lavedas wrote:

>> On May 27, 4:34 pm, "M" <[email protected]> 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)
 

My Computer

A

Al Dunbar

"Todd Vargo" <[email protected]> wrote in message
news:#[email protected]

> Al Dunbar wrote:

>> Tom Lavedas wrote:

>>> On May 27, 4:34 pm, "M" <[email protected]> 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)
 

My Computer

Top