Name
Public Statement
Syntax
Publicvarname[([subscripts])] _varname[([subscripts])]
-
varname Use: Required
Data Subtype: Any
The name of the variable, which must follow VBScript naming conventions (see “Rules at a Glance,” second bullet).
-
subscripts Use: Optional
Data Subtype: Integer or Long
Denotes
varnameas an array and optionally specifies the dimensions and number of elements of the array.
Description
Used in a script or a Class block to declare a
public variable and allocate the relevant storage space in memory. A
Public variable has script-level scope—that
is, it can be used by all procedures in a script. When used in a
class construct, it is visible outside the class project.
Rules at a Glance
The behavior of a
Publicvariable depends on where it’s declared, as the following table shows:
|
Variable Declared in... |
Scope |
|---|---|
|
Any procedure, Function or Property statement |
Illegal; generates a VBScript compilation; use the
|
|
Script-level code |
Variable is available throughout the script. |
|
Class block declarations section |
Variable is available as a property of the class to all code within the script. |
varnamefollows 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.The
subscriptsargument has the following syntax:upperbound[,upperbound]Using the
subscriptsargument, you can declare ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access