Programming Style

This manual follows the guidelines below in presenting Visual Basic code:

  • Reserved words are in lowercase with an initial capital letter.


    Dim intSomeValue As Integer, strTextValue As StringintStartNumber As Integer
    ' If, Then, and Str are reserved words.intSomeValue = 0 Then strTextValue = Str(intStartNumber)
  • Variable names begin with a lowercase prefix, followed by a lowercase word or words with an initial capital letter. Variables are declared at beginning of an example.


    Dim dblIncome As DoublestrFirstName As String * 30
    
  • Line labels are used instead of line numbers for error-handling routines and for On...GoSub and On...GoTo statements.


    On Error GoTo ErrorHandler
    .
    .
    .:
        MsgBox Err.Description
    
  • An apostrophe ( ' ) introduces a comment.


    ' This is a comment; these two lines
    ' are ignored when the program is running.
    
  • Control-flow blocks and statements in Sub and Function procedures are indented.


    Sub SomeCode ( )
        If intX > 0 Then
            intP = intQ
        End IfSub