Variable Naming Conventions

Follow this suggested format for naming variables.

[Scope]TypeName

Parameters

  • Scope
    Optional. A convention for noting the range of reference for the variable. For example, local variables can be prefixed with "l," which reminds you that they can be referenced only within the procedure they were defined in. Suggested expressions for Scope are as follows.
    Scope Description Example
    l Local
    lnCounter
    p Private (default)
    pnStatus
    g Public (global)
    gnOldRecno
    t Parameter
    tnRecNo
  • Type
    Convention for noting the data type of a variable. Suggested prefixes for Type are as follows.
    Type Description Example
    a Array
    aMonths
    c Character
    cLastName
    y Currency
    yCurrentValue
    d Date
    dBirthDay
    t Datetime
    tLastModified
    b Double
    bValue
    f Float
    fInterest
    l Logical
    lFlag
    n Numeric
    nCounter
    o Object
    oEmployee
    u Unknown
    uReturnValue

Remarks

Prefixes aren't required, but are recommended as good programming practice. Using a prefix does not dictate the value of a variable — in Visual FoxPro prefixes are used only as a naming convention. For example, adding the prefix "c" does not check that only character data is stored to the variable, but it does help you remember that the variable was created to accept character data.

Note   The scope prefix is recommended but not required. In some cases, explicit scoping does not apply. For example, in the main program of a stand-alone application there is no difference in visibility for variables scoped as PUBLIC or PRIVATE. The type prefix is always relevant and is required in sample programs.

For more information, see Visual FoxPro Naming Rules.

See Also

Constant Naming Conventions | Object Naming Conventions | Table Field Naming Conventions | Visual FoxPro Naming Rules | Window Naming Conventions