Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
MSDN Library

Public Statement

Declares public variables and allocates storage space. Declares, in a Class block, a public variable.


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

varname

Name of the variable; follows standard variable naming conventions.

subscripts

Dimensions of an array variable; up to 60 multiple dimensions may be declared. The subscripts argument uses the following syntax:

upper [, upper] . . .

The lower bound of an array is always zero.

Public statement variables are available to all procedures in all scripts.

A variable that refers to an object must be assigned an existing object using the Set statement before it can be used. Until it is assigned an object, the declared object variable is initialized as Empty.

You can also use the Public statement with empty parentheses to declare a dynamic array. After declaring a dynamic array, use the ReDim statement within a procedure to define the number of dimensions and elements in the array. If you try to redeclare a dimension for an array variable whose size was explicitly specified in a Private, Public, or Dim statement, an error occurs.

The following example illustrates the use of the Public statement:

Public MyNumber ' Public Variant variable.

Public MyArray(9) ' Public array variable.

' Multiple Public declarations of Variant variables.

Public MyNumber, MyVar, YourNumber

Community Additions

Show:
© 2015 Microsoft