Como: Definir várias versões de um procedimento (Visual Basic)
You can define a procedure in multiple versions by overloading it, using the same name but a different parameter list for each version. The purpose of overloading is to define several closely related versions of a procedure without having to differentiate them by name.
For more information, see Sobrecarga de procedimento (Visual Basic).
To define multiple versions of a procedure
Write a Sub or Function declaration statement for each version of the procedure you want to define. Use the same procedure name in every declaration.
Precede the Sub or Function keyword in each declaration with the Sobrecargas (Visual Basic) keyword. You can optionally omit Overloads in the declarations, but if you include it in any of the declarations, you must include it in every declaration.
Following each declaration statement, write procedure code to handle the specific case where the calling code supplies arguments matching that version's parameter list. Não é necessário para teste quais parâmetros o código de chamada tenha fornecido. Visual Basicpassa o controle para a versão correspondente do seu procedimento.
Terminate each version of the procedure with the End Sub or End Function statement as appropriate.
Exemplo
The following example defines a Sub procedure to post a transaction against a customer's balance. It uses the Overloads keyword to define two versions of the procedure, one that accepts the customer by name and the other by account number.
Overloads Sub post(ByVal custName As String, ByVal amount As Single)
' Insert code to access customer record by customer name.
End Sub
Overloads Sub post(ByVal custAcct As Integer, ByVal amount As Single)
' Insert code to access customer record by account number.
End Sub
The calling code can obtain the customer identification as either a String or an Integer, and then use the same calling statement in either case.
For information on how to call these versions of the post procedure, see Como: Chamar um procedimento sobrecarregado (Visual Basic).
Compilando o código
Make sure each of your overloaded versions has the same procedure name but a different parameter list.
Consulte também
Tarefas
Solucionando problemas de procedimentos (Visual Basic)
Como: Sobrecarregar um procedimento que recebe parâmetros opcionais (Visual Basic)
Como: Sobrecarregar um procedimento que recebe um número indefinido de parâmetros (Visual Basic)
Conceitos
Parâmetros e argumentos de procedimento (Visual Basic)
Considerações sobre procedimentos de sobrecarga (Visual Basic)