SoFunction
Updated on 2025-04-10

VBS tutorial: VBscript statement-Private statement

Private statement

Define private variables and allocate storage space. existClassDefine private variables in blocks.

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

parameter

varname

The name of the variable; follows the standard variable naming convention.

subscripts

The dimension of an array variable, you can declare an array of up to 60 dimensions.subscriptsParameters use the following syntax:

upper [, upper] . . .

The lower bound of the array is always 0.

illustrate

Private statement variables can only be used in scripts that declare the variable.

Before using variables that reference objects, you must useSetThe statement assigns an existing object to this variable. Before assignment, the declared object variable is initialized by Empty.

You can also use empty bracketsPrivateStatement declares dynamic arrays. After declaring a dynamic array, it can be used within the processReDimThe statement defines the dimensions and elements of the array. IfPrivate, Public orDimAn error occurs when an array size has been explicitly specified in the statement but attempts to redeclare the array dimension.

NoticeUsed in the processPrivate When a statement isPrivate The statement is placed at the beginning of the process.

The following example shows how to use itPrivateStatement:

Private MyNumber   ' Private Variant variable.Private MyArray(9)   ' Private array variable.   ' Multiple Private declarations of Variant variables.Private MyNumber, MyVar, YourNumber