1. Computing
Send to a Friend via Email

Procedures in VB.NET

Exploring the ways procedures are used


At first glance, this may seem like a fairly trivial operation. After all, what we're talking about is simple code like this:

Calling the procedure ...

Dim TestArgument As String = "ABCDEF"

The procedure definition ...

Sub TestSubroutine( _
   ByVal TestParameter As String)
   ' Your code goes here
End Sub

But there are a host of complications that can come up in the real world. For example, what if the parameter that is passed is an array or a array? What if it doesn't have a fixed number of elements? How do you pass optional parameters? And there is a lot of additional code that can be used in procedures that isn't shown in our simple example. Since one of the fundamental rules of Visual Basic is that every line of code must be inside some sort of procedure, it's important that we get this right.

There are several types of procedures to choose from, however. In addition to Sub procedures (which is the focus of most of this article), there are Function procedures, property procedures (Get and Set), and the somewhat obscure Operator procedure.

First, the terms argument and parameter are constantly misused, so let's clear that up. According to Microsoft, the procedure call statement contains arguments. (TestArgument above.) The procedure itself defines zero or more parameters. TestParameter is the only parameter defined above.

©2014 About.com. All rights reserved.