Compartilhar via


Como: chamar um procedimento que recebe um número indefinido de parâmetros (Visual Basic)

A procedure can declare the last entry in its parameter list to be a parameter array. This allows it to accept an indefinite number of values for that parameter, instead of just a single value.

For more information, see Matrizes de parâmetros (Visual Basic).

To call a procedure with a parameter array and omit the corresponding argument

  1. Write the procedure call in the normal way. The parameter array must be the last argument.

  2. Terminate the argument list with the next-to-last argument. The parameter array is optional, and all the preceding parameters must be required.

    - ou -

    Supply the Nothing keyword as the argument for the parameter array.

  3. Visual Basic passes an empty one-dimensional array to the procedure for the parameter array.

To call a procedure with a parameter array and supply a list of arguments

  1. Write the procedure call in the normal way. The parameter array must be the last argument.

  2. Supply any number of arguments, separated by commas, for the parameter array. The data type of each argument must be implicitly convertible to the ParamArray element type.

  3. Visual Basic passes a one-dimensional array to the procedure, containing all the values you supplied.

To call a procedure with a parameter array and supply an array of arguments

  1. Write the procedure call in the normal way. The parameter array must be the last argument.

  2. For the parameter array, supply a one-dimensional array with the same element type as the parameter array's element type.

  3. Visual Basic passes your array to the procedure.

Exemplo

The following examples show typical calls to the studentScores procedure defined in Como: definir um procedimento com um número indefinido de parâmetros (Visual Basic).

Call studentScores("George")


...


Call studentScores("Anne", "10", "26", "32", "15", "22", "24", "16")
Call studentScores("Mary", "High", "Low", "Average", "High")
Dim JohnScores() As String = {"35", "Absent", "21", "30"}
Call studentScores("John", JohnScores)

The first call omits the parameter array altogether and supplies only the required first argument. The studentScores procedure treats this call as passing an empty array.

The second and third calls supply argument lists of different lengths to the parameter array. Each such list is passed as an array of values.

The fourth call passes an array to the parameter array.

Consulte também

Referência

Opcional (Visual Basic)

ParamArray (Visual Basic)

ByVal (Visual Basic)

UBound

Conceitos

Parâmetros e argumentos de procedimento (Visual Basic)

Passando argumentos por valor e por referência (Visual Basic)

Passagem de argumentos por posição e nome (Visual Basic)

Parâmetros opcionais (Visual Basic)

Sobrecarga de procedimento (Visual Basic)

Verificação de Tipo no Visual Basic