Passing parameters - VBA

Hello Readers,

Welcome to Coding by Learning !!! 😀 

Most of the programming languages has the concept of passing parameters to functions in different ways. Python, C, C++ and Java programming languages have the concept in the name of Call by value and Call by reference.

In VBA , It is arrived using keywords ByVal and ByRef.


Difference between ByVal and ByRef




















Now lets see the concepts with an example

Here in the example, I have written a sub procedure for calculating sum of 2 numbers. I have created 2 functions "add2Numbers_byval" and "add2Numbers_byref" for differentiating the concepts.








Output as follows :-














Look at the output. The value of iNum2 is same using ByVal and It is modified using By Ref.

Happy learning & Happy Coding !!!

Comment and share this post to your friends and colleagues 😀

Comments

  1. Helped me understood clearly...

    ReplyDelete
  2. I face this question when in vba interview. This blog helps me to understand the concept easily.

    ReplyDelete
    Replies
    1. Happy to know our blog helped you :), Thanks for the support

      Delete

Post a Comment

Popular posts from this blog

VBA Interview Questions - Part 2 - Variables and Data types

VBA Interview questions - screen updating

VBA Interview questions - Part 3 - Array concept