Visual Basic

Functions and Subroutines

Public functions and subroutines have scope prefixes in the same way that variables do. Public and private functions also have a type prefix that reflects the type of value returned. The rules for choosing the type prefix are the same as those for variables.

Private subroutines

Private subroutines and functions do not require scope prefixes. Here are some examples of private subroutines:

  Private Sub OpenLogFile()
  Private Sub ClearGrid()

And here are some private functions:

  Private Function nGetNextItem() As Integer
  Private Function sGetFullPath(ByVal sFileName As String) _
  As String
  Private Function CGetNextCell() As CTableEntry

Public subroutines

The rules for choosing scope prefixes for public subroutines are exactly the same as those for variables, as shown here:

  Public ErReportError()
  Public TbInsertTableEntry()
  Public DbDeleteItem()

Form and class methods

Public functions and subroutines defined in classes and forms are properties and do not have type or scope prefixes.

Form and class properties (protected)

Property Let, Property Set, and Property Get routines do not have type or scope prefixes.

DLL procedures

When declaring Windows API functions, we use the Alias keyword to add the prefix Win. For example, CallWindowProc becomes WinCallWindowProc. When declaring functions in other DLLs, we use the prefix Dll.

Parameter lists

Formal parameters are named as local variables but with i or o added in place of a scope prefix to denote whether the parameter is an input or an output:

  Sub CrackURL(ByVal siURL As String, ByRef soProtcol, _
      ByRef soPath, ByRef soPath, ByRef noPort)

For parameters that are both inputs and outputs, we use io.