Home TechnologyProgramming Subscribe to RSS

What Is Use Of Keyword ParamArray In Visual Basic?

Define the use of ParamArray.

Answer Question

1 Answer - Sort by: Date | Rating

    Sometimes we need a  procedure that can accepts a variable number of arguments at various times during program( it means the procedure is sometimes called by passing  one argument and at some later time same procedure can be called by passing two arguments etc.).

    In this case we use the keyword ParamArray in definition header of the procedure that requires the variable number of arguments at various times.
    We put this keyword in the parameter list that indicates that this procedure will receive a variable number of arguments.

    The keyword ParamArray is preceded by the declaration of Variant array in the parameter list of that procedure.
    Variant type array is used to enable the user to pass the arguments of any type.
    The syntax of using this keyword ParamArray in procedure definition is given as:
                              Private sub myfun ( ParamArray x () as variant)
                               Dim y as integer  

                               For y=LBound(x) to UBound(x)
                                   Print x(y)
                               Next
                              End sub
    Where 'myfun' is a procedure that uses ParamArray .this procedure can be called by passing various numbers of arguments as:
                               Call myfun (1)
                                Call myfun (1, 2)
                                  Call myfun (1, 2, 3)
    We can also pass the different number of arguments as well as the different types of arguments like:
                             Call myfun (1, "fun", 5.67)
    The above call passes the three different types of arguments .
    0 0

    Raaga 

    answered 3 years ago

      More

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store