How to: Call an Overloaded Procedure (Visual Basic)
The advantage of overloading a procedure is in the flexibility of the call. The calling code can obtain the information it needs to pass to the procedure and then call a single procedure name, no matter what arguments it is passing.
To call a procedure that has more than one version defined
In the calling code, determine which data to pass to the procedure.
Write the procedure call in the normal way, presenting the data in the argument list. Be sure the arguments match the parameter list in one of the versions defined for the procedure.
You do not have to determine which version of the procedure to call. Visual Basic passes control to the version matching your argument list.
The following example calls the
post
procedure declared in How to: Define Multiple Versions of a Procedure. It obtains the customer identification, determines whether it is aString
or anInteger
, and then in either case calls the same procedure.Imports MSVB = Microsoft.VisualBasic
Dim customer As String Dim accountNum As Integer Dim amount As Single customer = MSVB.Interaction.InputBox("Enter customer name or number") amount = MSVB.Interaction.InputBox("Enter transaction amount") Try accountNum = CInt(customer) Call post(accountNum, amount) Catch Call post(customer, amount) End Try
See also
- Procedures
- Procedure Parameters and Arguments
- Procedure Overloading
- Troubleshooting Procedures
- How to: Define Multiple Versions of a Procedure
- How to: Overload a Procedure that Takes Optional Parameters
- How to: Overload a Procedure that Takes an Indefinite Number of Parameters
- Considerations in Overloading Procedures
- Overload Resolution
- Overloads