Results 1 to 4 of 4

Thread: What is the purpose of Parameters

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2011
    Posts
    1

    Question 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

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    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

  3. #3
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: What is the purpose of Parameters

    Quote Originally Posted by Sellion View Post
    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.

  4. #4
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    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.
    Doctor Ed

Posting Permissions

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



Click Here to Expand Forum to Full Width