What is the purpose of Parameters
Sorry, I'm kind of new to programming but something I am having difficulty understanding is parameters. What are they and when are they used? I saw some examples of parameters and I noticed that they are similar to variables. What is the difference between a parameter and a variable? Since I'm a beginner, it would be nice if anyone could explain this in simple terms.
Thanks in advance :)
Re: What is the purpose of Parameters
Parameters are useful when you need to reuse some common function/procedure...
Code:
Public Function Test(a As Integer, b As Integer, Optional c As Integer = 0) As Long
Test = a + b + c
End Function
Now, try passing to that function say 1,2 or 3,4 or 1,2,3 - results of course will be different (3, 7 and 6).
As you probably noticed most of VB intrinsic functions/methods/etc do require parameters although some of them could be optional:
Left$(string, length)
Mid$(string, start, [length]) <<< parameter in brackets is optional
Re: What is the purpose of Parameters
Quote:
Originally Posted by
Sellion
Sorry, I'm kind of new to programming but something I am having difficulty understanding is parameters. What are they and when are they used? I saw some examples of parameters and I noticed that they are similar to variables. What is the difference between a parameter and a variable? Since I'm a beginner, it would be nice if anyone could explain this in simple terms.
Parameters are variables that you pass to functions. The advantage to using parameters instead of global variables is that parameters make your functions more generic, which makes them more easily copied from project to project.
In buzzword-speak, parameters can be viewed as a primitive form of encapsulation that increases the reusability of your code.
Re: What is the purpose of Parameters
To my knowledge, parameters have been around for at least 50 years and both Ellis Dee and Rhino have defined them very well in this thread. I suggest that you use them whenever you can as you write your code. :ehh: