Visual Basic

Controls and Forms

We also use type prefixes when naming Visual Basic controls. The prefixes are given at the end of this appendix. Forms are named as if they were controls, even though a form name can also act as a class name. For example, we would name a form frmPublication instead of CPublication, even though we could create new instances of the form:

  Dim frmNewPub As New frmPublication

Constants

Constants are named in uppercase letters, with no type or scope prefixes. Arbitrary prefixes can be used to group sets of related constants:

  Const TABLE_SIZE            As Integer = 100
  Const DEFAULT_LOG_FILE      As String = "log.txt"
  Const ERR_GENERIC           As Integer = 32767
  Const ERR_LOGON_FAIL        As Integer = 32766
  Const ERR_COMPONENT_MISSING As Integer = 32765

Type and Class Definitions

Type names are prefixed with t, and class names are prefixed with C. These prefixes are also used as the base-type prefixes when naming instances. The rest of the name is written in mixed case:

  Type tTableEntry
      nNewState As Integer
      lAction   As Long
  End Type

And in use:

  Dim tCell         As tTableEntry
  Dim CSymbolTable  As New CTable

Source Files

Source filenames are restricted to the traditional 8.3 format. The first three characters are reserved for a project identifier, and the default file extensions are retained. The remaining five characters are used to distinguish files in whatever way seems appropriate.

OtherNaming Conventions

This is an example of a local string:

  Dim sCustomerName As String

This is an example of a module-level integer:

  Dim nmCustomerId As Integer

Here is a global-level Double defined in the module Mi:

  Public dPuMiCustomerNumber As Double

Here is a global-level Double; the module identifier is not defined or else resident in the project-wide globals module.

  Public dPuCustomerNumber As Double

This is a global array of Longs. The module identifier is not defined or else resident in the project-wide globals module.

  Public alPuAmounts(1 to 25) As Long

This is a global database. The module identifier is Dt:

  Public dbPuDtCustomers As Database

This shows a call to an external DLL function; the result is assigned to a global variable resident in the project-wide global's module.

  bPuRetCode = bDllIsShareLoaded ()