VB Procedures

VB Procedures

A VB.NET procedure (aka sub for subroutine) is defined using the Sub / End Sub keywords. The procedure is invoked by using its name as a statement or, optionally, by preceding its name with the Call keyword.

The sub name must conform to same naming rules as for variables in VB.NET. The sub name can be defined and used in either uppercase or lowercase, so a sub named ABC can be called as either abc, ABC, abC, AbC, aBC, etc. By standard coding convention however, sub names use capital letters at the start of the words as in:

Good

Not recommended

Sub EvaluateScore
  Sub GetDataResult
  Sub ParseUserData

Sub GreenBall
  Sub A
  Sub caltrimaccesstime


In the example below if a sub makes a call to the myProcedureB sub, then the sub myProcedureA will also be called.

                       

In Visual Studio procedures and functions are visually separated by a thin gray horizontal line. Any number of blank lines may be added above and below the line for readability.

A procedure may call itself. This is called direct recursion. Do not try the following example which results in an infinite loop.

A sub must have only one End Sub.

The Exit Sub statement can be used within a sub to exit the sub immediately.

Subs may not be defined inside another sub.

A sub may have zero or more parameters.

VB.NET supports overloaded procedures. The signatures are based on the types and number of parameters.

posted @ 2015-06-17 00:24  xymum  阅读(67)  评论(0编辑  收藏  举报