Name
Private Statement
Syntax
Private [WithEvents]varname[([subscripts])] [As [New] _type] [, [WithEvents]varname[([subscripts])]_ [As [New]type]] . . .
-
WithEvents Use: Optional
Type: Keyword
A keyword that denotes the object variable,
varname, can respond to events triggered from within the object to which it refers.-
varname Use: Required
Data Type: Any
The name of the variable, following Visual Basic naming conventions.
-
subscripts Use: Optional
Data Type: Integer or Long
Denotes
varnameas an array and specifies the number and extent of array dimensions.-
New Use: Optional
Type: Keyword
Used to automatically create an instance of the object referred to by the object variable,
varname.-
type Use: Optional
Type: Keyword
Data type of the variable
varname.
Description
Used at module level to declare a private variable and allocate the relevant storage space in memory. Private can also be used with procedures and class modules.
Rules at a Glance
A
Privatevariable’s scope is limited to the module in which it is created.WithEventsis only valid when used to declare an object variable. TheWithEventskeyword informs VB that the object being referenced exposes events. When you declare an object variable usingWithEvents, an entry for the object variable is placed in the code window’s Object List, and a list of the events available to the object variable is placed in its Procedures List. You can then write code in the object variable’s event handlers in the same way you write other more common ...
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