Como: Passar argumentos para um procedimento (Visual Basic)

When you call a procedure, you follow the procedure name with an argument list in parentheses. You supply an argument corresponding to every required parameter the procedure defines, and you can optionally supply arguments to the Optional parameters. If you do not supply an Optional parameter in the call, you must include a comma to mark its place in the argument list if you are supplying any subsequent arguments.

If you intend to pass an argument of a data type different from that of its corresponding parameter, such as Byte to String, you can set the type-checking switch (Opção declaração estrito) to Off. If Option Strict is On, you must use either widening conversions or explicit conversion keywords. For more information, see Conversões de expansão e restrição (Visual Basic) and Funções de conversão de tipo (Visual Basic).

For more information, see Parâmetros e argumentos de procedimento (Visual Basic).

To pass one or more arguments to a procedure

  1. In the calling statement, follow the procedure name with parentheses.

  2. Inside the parentheses, put an argument list. Include an argument for each required parameter the procedure defines, and separate the arguments with commas.

  3. Make sure each argument is a valid expression that evaluates to a data type convertible to the type the procedure defines for the corresponding parameter.

  4. If a parameter is defined as Opcional (Visual Basic), you can either include it in the argument list or omit it. If you omit it, the procedure uses the default value defined for that parameter.

  5. If you omit an argument for an Optional parameter and there is another parameter after it in the parameter list, you can mark the place of the omitted argument by an extra comma in the argument list.

    O exemplo a seguir chama o Visual Basic MsgBoxdefunção.

    Dim mbResult As MsgBoxResult
    Dim displayString As String = "Show this string to the user"
    mbResult = MsgBox(displayString, , "Put this in the title bar")
    

    The preceding example supplies the required first argument, which is the message string to be displayed. It omits an argument for the optional second parameter, which specifies the buttons to be displayed on the message box. Because the call does not supply a value, MsgBox uses the default value, MsgBoxStyle.OKOnly, which displays only an OK button.

    The second comma in the argument list marks the place of the omitted second argument, and the last string is passed to the optional third parameter of MsgBox, which is the text to be displayed in the title bar.

Consulte também

Tarefas

Como: Definir um parâmetro para um procedimento (Visual Basic)

Conceitos

Subprocedimentos (Visual Basic)

Procedimentos de função (Visual Basic)

Procedimentos de propriedade (Visual Basic)

Procedimentos de operador (Visual Basic)

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

Procedimentos recursivos (Visual Basic)

Sobrecarga de procedimento (Visual Basic)

Programação orientada a objeto (C# e Visual Basic)

Outros recursos

Objetos e Classes no Visual Basic