Naming Conventions
VBA programs can quickly become quite complicated so we can use all the help we can in trying to make them as readable as possible.
Often as time passes and we move on to other projects the original ideas behind the program fade and we rely on readable code to refresh our memory.
An easy way to make programs more readable is to use a consistent naming convention throughout.
This should not only apply to variables but also to constants, procedures and all other items.
Constants
Constants - ALL CAPITALS
Const m_iMODULELEVEL As Integer = 100
Public Const g_iPROJECTLEVEL As Integer = 100
Public Sub MySubroutine()
Const sPROCEDURELEVEL As String = "text"
Variables
Variables must begin with a letter or an underscore
It should remind you of its purpose (always use a descriptive name).
Variables (local level) - Hungarian
Variables are prefixed with an abbreviation that indicates its data type.
For example prefixing a variable with "s" indicates that it is a string.
Dim sMyString As String
Dim iMyNumber As Integer
For a list of all the common prefixes, please refer to the Data Types section.
Variables (module level) - PascalCase
Initial uppercase for variable names
No data type prefix to help distinguish them
Dim VariableName As Object
Subroutines
PascalCase
Functions
camelCase
Initial lowercase for variable names
Dim variableName As Object
Classes
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext