Code Samples and Programming Style

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Microsoft® Office XP Developer Help contains numerous code samples that you can use to experiment with the concepts covered. Unless otherwise noted, the code is compatible with Microsoft® Visual Basic® for Applications (VBA) 6.0 as it is implemented in Visual Basic 6.0, Microsoft® Access, Microsoft® Excel, Microsoft® FrontPage®, Microsoft® Outlook®, Microsoft® PowerPoint®, Microsoft® Word, and other applications that host VBA 6.0. Additional code samples are written in Visual Basic Scripting Edition (VBScript), Microsoft® JScript®, HTML, and DHTML.

Help uses the following conventions in VBA sample code:

  • Keywords appear with an initial letter capitalized; concatenated words might contain other capital letters. Variables appear in mixed case, constants in uppercase.

    Dim objDatabase As Object
       Const PROP_NOT_FOUND_ERROR = 3270
    
       Set objDatabase = CurrentDb
    
  • In full procedures, all variables are declared locally or are listed with an initialization procedure that declares public variables. All code has been tested with the VBA Option Explicit statement to make sure there are no undeclared variables.

  • An apostrophe (') introduces a comment:

    ' This is a comment.
    Dim intNew As Integer  ' This is also a comment.
    
  • Control-flow blocks and statements in Sub, Function, and Property procedures are indented:

    Sub MyCode ()
       Dim intX As Integer
       Dim intP As Integer
       Dim intQ As Integer
    
       If intX > 0 Then
          intP = intQ
       End If
    End Sub
    
  • Naming conventions are used to make it easier to identify objects and variables in the code samples. For more information about naming conventions, see Writing Solid Code.

Help also uses the following convention in HTML script samples:

  • The HTML and DHTML naming conventions use a lowercase or lowercase and uppercase concatenated style for object, variable, method, event, function, and property names. For example, the name of the document object is lowercase, whereas the name of the srcElement property is a concatenated lowercase and uppercase combination.

See Also

Getting Started with Office Developer | Typographic Conventions | Using the Code Samples