Results 1 to 5 of 5

Thread: Forcing an Argument to be Passed by Value

  1. #1
    Member Transformer's Avatar
    Join Date
    Mar 2012
    Posts
    91
    Rep Power
    13

    Lightbulb Forcing an Argument to be Passed by Value

    UsefulGyaan Has Posted the Following On 05-20-2013 10:22 PM:

    While creating a subroutine we can define whether arguments will be passed ByVal *or ByRef however this behavior can be overridden as discussed below. Let’s say we have a procedure Append which accepts an argument by reference.However at the time of calling the procedure, if argument is enclosed in parentheses then it is treated as […]





    Forcing an Argument to be Passed by Value

  2. #2
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    The following addition to Transformer's message is based on my deduction which I believe to be factual because it is consistent whenever it crops up (but I have no "proof" of its truthfulness because I really do not know about all of the actual underlying processes taking place in VB). ByRef arguments pass the memory location of the variable to the routine and any changes made to the argument during processing writes those changes directly to the memory location passed into the function for that argument. For ByVal arguments, VB makes a copy of the argument and passes in the memory location for that copy into the function... any changes made to the "ByRef argument" get written directly to the memory location passed into the function for that argument (as is the case with the ByRef argument), but since the memory location is to a copy of the actual value, those changes do not affect the original arugument.

    Now, whenever you use a parentheses in VB code that is not required by syntax, VB assumes a calculation will take place (even if only one "thing" is inside the parentheses... the calculation of the expression inside the parentheses just results in the "one thing" that was passed in). To do that calculation, VB finds an unusued memory location and carries the calculation out there, returning the memory location for that calculated value to the postion of the parentheses for inclusion into the expression inside the parentheses (remember, everything is in a memory location for an expression being evaluated). So, if you put an argument in parentheses, that argument is stored in a memory location and it is that memory location that gets passed into the function. This is exactly the process that passing an argument ByVal follows, so effectively, passing an argument in parentheses performs exactly the same as passing that same argument ByVal.
    Last edited by Rick Rothstein; 05-21-2013 at 11:26 AM.

  3. #3
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    @ Transformer

    The blog readers will get benefitted these additional comments (Rick's), if you provide a link in your blog.


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgxzpgHWTLGj0C3q3gx4AaABAg. 9gxsUMU53al9k5c8W6QGE8
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugz2PzvZTJyxHz70eVF4AaABAg. 9gxDYq2iiZ89h4ISxLD17d
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugz2PzvZTJyxHz70eVF4AaABAg. 9gxDYq2iiZ89h4LdsDETim
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugz2PzvZTJyxHz70eVF4AaABAg. 9gxDYq2iiZ89h32czjtyR_
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgxzpgHWTLGj0C3q3gx4AaABAg
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugw_smEwvNffCPr_nrB4AaABAg. 9gvyL53lI1l9gxwd_9-V6z
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugy7vmiHsQ0oUt2QCPZ4AaABAg. 9gvoy4OW6lU9gxwxC5-rL9
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgzuX3uYmqJRtsZIbqF4AaABAg. 9gth61YhXKB9gxxCMdRLA0
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgxcPC64RQGmXwO5rft4AaABAg. 9gtQLXaeg0e9gxxNuc5CCM
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgwCY8vOs1DFHgYSJwF4AaABAg. 9godrFcyWYw9gxy1odpiRj
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgyL5nh_j8w70-YBoUt4AaABAg.9goMcRjwjtc9gxyslvuZKx
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgwwWRgmRZNqJKptHR14AaABAg. 9go-DbayTZa9gxzPbefHXf
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgwF3wECwc8tVoRmz6B4AaABAg. 9go-5xLQM8P9gxzmB7nkVQ
    https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgyRDmGTHnMdT7dl_qx4AaABAg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 07-11-2023 at 12:24 PM.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  4. #4
    Member Transformer's Avatar
    Join Date
    Mar 2012
    Posts
    91
    Rep Power
    13
    Ok i'll do that and I've given forum's link there on the blog.
    Regards,

    Transformer

  5. #5
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Quote Originally Posted by Transformer View Post
    ...I've given forum's link there on the blog.
    thanks.
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Custom Spin Button Based On Values Passed From Array
    By Preeti Verma in forum Excel Help
    Replies: 7
    Last Post: 05-22-2012, 07:23 PM
  2. Worksheet Protection Method with UserInterfaceOnly Argument
    By technicalupload in forum Download Center
    Replies: 1
    Last Post: 09-02-2011, 04:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •