Visual Basic Concepts

Visual Studio 6.0

Document Conventions

This documentation uses the following typographic conventions.

Example of convention Description
Sub, If, Case Else, Print, True, BackColor, Click, Debug, Long Words with initial letter capitalized indicate language-specific keywords.
setup Words you’re instructed to type appear in bold.
event-driven In text, italic letters can indicate defined terms, usually the first time they occur in the book. Italic formatting is also used occasionally for emphasis.
variable In syntax and text, italic letters can indicate placeholders for information you supply.
[expressionlist] In syntax, items inside square brackets are optional.
{While | Until} In syntax, braces and a vertical bar indicate a choice between two or more items. You must choose one of the items unless all of the items also are enclosed in square brackets.
Sub HelloButton_Click()
Readout.Text = _
"Hello, world!"
End Sub

This font is used for code.
ENTER Capital letters are used for the names of keys and key sequences, such as ENTER and CTRL+R.
ALT+F1 A plus sign (+) between key names indicates a combination of keys. For example, ALT+F1 means to hold down the ALT key while pressing the F1 key.
DOWN ARROW Individual direction keys are referred to by the direction of the arrow on the key top (LEFT, RIGHT, UP, or DOWN). The phrase "arrow keys" is used when describing these keys collectively.
BACKSPACE, HOME Other navigational keys are referred to by their specific names.
c:\Vb\Samples\Calldlls.vbp Paths and file names are given in mixed case.

Programming Style in This Manual

The following guidelines are used in writing programs in this manual. For more information, see Programming Fundamentals in the Programmer's Guide.

  • Keywords appear with initial letters capitalized:
    ' Sub, If, ChDir, Print, and True are keywords.
    Print "Title Page"
  • Line labels are used instead of line numbers. The use of line labels is restricted to error-handling routines:
       Power = conFailure
    End Function
  • An apostrophe (') introduces comments:
    ' This is a comment; these two lines
    ' are ignored when the program is running.
  • Control-flow blocks and statements in Sub, Function, and Property procedures are indented from the enclosing code:
    Private Sub cmdRemove_Click ()
       Dim Ind As Integer
       Ind = lstClient.ListIndex   ' Get index.
       ' Make sure list item is selected.
       If Ind >= 0 Then
          lstClient.RemoveItem Ind   ' Remove it
                                  ' from list box.
          ' Display number.
          lblDisplay.Caption = lstClient.ListCount
          Beep                ' If nothing selected, beep.
       End If
    End Sub
  • Lines too long to fit on one line (except comments) may be continued on the next line using a line-continuation character, which is a single leading space followed by an underscore ( _):
    Sub Form_MouseDown (Button As Integer, _
    Shift As Integer, X As Single, Y As Single)
  • Intrinsic constant names are in a mixed-case format, with a two-character prefix indicating the object library that defines the constant. Constants from the Visual Basic (VB) and Visual Basic for applications (VBA) object libraries are prefaced with a "vb"; constants from the data access (DAO) object library are prefaced with a "db"; constants from the Microsoft Excel object library are prefaced with an "xl". For example:

    Throughout this book, user-defined constants are usually prefaced with "con" and are mixed case. For example:


    When using Windows API constants, however, the code examples still follow the same conventions as in previous versions of Visual Basic. For example: