Compartilhar via


Como: Chamar um procedimento que não retorna um valor (Visual Basic)

A Sub procedure does not return a value to the calling code. You call it explicitly with a stand-alone calling statement. You cannot call it by simply using its name within an expression.

The calling statement can optionally use the Call keyword. This is recommended, because it improves the readability of your code.

To call a Sub procedure

  1. Use a Call statement, following the Call keyword with the name of the Sub procedure.

  2. Follow the procedure name with parentheses to enclose the argument list. If there are no arguments, you can optionally omit the parentheses. However, using the parentheses makes your code easier to read.

  3. Place the arguments in the argument list within the parentheses, separated by commas. Be sure you supply the arguments in the same order that the Sub procedure defines the corresponding parameters.

    O exemplo a seguir chama o Visual Basic AppActivatefunção para ativar umajanelade aplicativo. AppActivateleva o título da janela como seu único argumento. It does not return a value to the calling code. Se um processo de bloco de notas não estiver sendo executado, o exemplo lança uma ArgumentException. The Shell procedure assumes the applications are in the paths specified.

    Dim notepadID As Integer
    ' Activate a running Notepad process.
    AppActivate("Untitled - Notepad")
    ' AppActivate can also use the return value of the Shell function.
    ' Shell runs a new instance of Notepad.
    notepadID = Shell("C:\WINNT\NOTEPAD.EXE", AppWinStyle.NormalFocus)
    ' Activate the new instance of Notepad.  
    AppActivate(notepadID)
    

Consulte também

Tarefas

Como: Criar um procedimento (Visual Basic)

Como: Chamar um procedimento que retorna um valor (Visual Basic)

Como: chamada um manipulador de eventos em Visual Basic

Referência

Instrução Sub (Visual Basic)

Shell

ArgumentException

Conceitos

Procedimentos no Visual Basic

Subprocedimentos (Visual Basic)

Parâmetros e argumentos de procedimento (Visual Basic)