Name

Private Statement

Syntax

Private varname[([subscripts])] [, varname[([subscripts])] . . .
varname

Use: Required

Variant Type: Any

The name of the variable, following Visual Basic naming conventions.

subscripts

Use: Optional

Variant Type: Integer or Long

Denotes varname as an array and optionally specifies the number and extent of array dimensions.

Description

Used in a script or in a class to declare a private variable and allocate the relevant storage space in memory.

Rules at a Glance

  • A Private variable’s visibility is limited to the script in which it’s created for global variables and to the class in which it is declared for class-level variables. Elsewhere, the Private keyword generates an error.

  • varname follows standard VB naming conventions. It must begin with an alphabetic character, can’t contain embedded periods or spaces, can’t be the same as a VBScript reserved word, must be shorter than 255 characters, and must be unique within its scope.

  • You can override standard variable naming conventions by placing your variable name in brackets. This allows you to use reserved words or illegal characters in variable names. For example:

    Private [me]
    Private [1Var]
    Private [2-Var]
  • The subscripts argument has the following syntax:

                            upperbound [,upperbound]...

    For example:

    Private strNames(10)

    defines an array of 11 elements (an array whose lower bound is 0 and whose upper bound is 10). Similarly:

    Private lngPrices(10, 10)

    defines a two-dimensional array of eleven elements in each dimension.

  • Using the ...

Get VBScript in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.