Private Statement |
Named Arguments
No
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 varname as an array and specifies the number and extent of array dimensions.
New
Use: Optional
Type: Keyword
Automatically creates an instance of the object referred to by the object variable varname.
type
Use: Optional
Data type of the variable varname.
Description
Used at module level to declare a private variable and allocate the relevant storage space in memory.
Rules at a Glance
A Private variable's scope is limited to the module in which it's created.
WithEvents is only valid when used to declare an object variable. The WithEvents keyword informs VB that the object being referenced exposes events. When you declare an object variable using WithEvents, 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 that you write other more common event handlers like Form_Load.
There is no limit ...
Get VB & VBA in a Nutshell: The Language 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.