Name
Public Statement
Syntax
Publicvarname[([subscripts])] _varname[([subscripts])]
varnameUse: Required
Data Type: Any
The name of the variable, which must follow VBScript naming conventions (see the second bullet in “Rules at a Glance”).
subscriptsUse: Optional
Data Type: 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 global 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 syntax error; use the
|
Global 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. |
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:
Public [me] Public [1Var] Public [2-Var]
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, ...
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