PDA

View Full Version : Forcing an Argument to be Passed by Value



Transformer
05-20-2013, 10:00 PM
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 […]http://stats.wordpress.com/b.gif?host=usefulgyaan.wordpress.com&blog=50473542 &post=758&subd=usefulgyaan&ref=&feed=1





Forcing an Argument to be Passed by Value (http://usefulgyaan.wordpress.com/2013/05/20/forcing-an-argument-to-be-passed-by-value/)

Rick Rothstein
05-20-2013, 10:52 PM
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.

Admin
05-21-2013, 09:32 AM
@ 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/channel/UCnxwq2aGJRbjOo_MO54oaHA)
https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgxzpgHWTLGj0C3q3gx4AaABAg.9gxsUMU53al9k5c8W6QG E8 (https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgxzpgHWTLGj0C3q3gx4AaABAg.9gxsUMU53al9k5c8W6QG E8)
https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugz2PzvZTJyxHz70eVF4AaABAg.9gxDYq2iiZ89h4ISxLD1 7d (https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugz2PzvZTJyxHz70eVF4AaABAg.9gxDYq2iiZ89h4ISxLD1 7d)
https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugz2PzvZTJyxHz70eVF4AaABAg.9gxDYq2iiZ89h4LdsDET im (https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugz2PzvZTJyxHz70eVF4AaABAg.9gxDYq2iiZ89h4LdsDET im)
https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugz2PzvZTJyxHz70eVF4AaABAg.9gxDYq2iiZ89h32czjty R_ (https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=Ugz2PzvZTJyxHz70eVF4AaABAg.9gxDYq2iiZ89h32czjty R_)
https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgxzpgHWTLGj0C3q3gx4AaABAg (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=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=Ugy7vmiHsQ0oUt2QCPZ4AaABAg.9gvoy4OW6lU9gxwxC5-rL9)
https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgzuX3uYmqJRtsZIbqF4AaABAg.9gth61YhXKB9gxxCMdRL A0 (https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgzuX3uYmqJRtsZIbqF4AaABAg.9gth61YhXKB9gxxCMdRL A0)
https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgxcPC64RQGmXwO5rft4AaABAg.9gtQLXaeg0e9gxxNuc5C CM (https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgxcPC64RQGmXwO5rft4AaABAg.9gtQLXaeg0e9gxxNuc5C CM)
https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgwCY8vOs1DFHgYSJwF4AaABAg.9godrFcyWYw9gxy1odpi Rj (https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgwCY8vOs1DFHgYSJwF4AaABAg.9godrFcyWYw9gxy1odpi Rj)
https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgyL5nh_j8w70-YBoUt4AaABAg.9goMcRjwjtc9gxyslvuZKx (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=UgwwWRgmRZNqJKptHR14AaABAg.9go-DbayTZa9gxzPbefHXf)
https://www.youtube.com/watch?v=xLCWtC6UYrM&lc=UgwF3wECwc8tVoRmz6B4AaABAg.9go-5xLQM8P9gxzmB7nkVQ (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/watch?v=xLCWtC6UYrM&lc=UgyRDmGTHnMdT7dl_qx4AaABAg)
https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA (https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA)

Transformer
05-21-2013, 11:13 AM
Ok i'll do that :) and I've given forum's link there on the blog.

Admin
05-21-2013, 11:28 AM
...I've given forum's link there on the blog.

thanks.