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
varname
as 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
Public
variable 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. |
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.The
subscripts
argument has the following syntax:upperbound
[,upperbound
]Using the
subscripts
argument, you can declare ...
Get VBScript in a Nutshell 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.