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.




Reply With Quote
Bookmarks