O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Private Statement

Syntax

Private [WithEvents] varname[([subscripts])] [As [New] _
        type] [, [WithEvents] varname[([subscripts])] _ 
        [As [New] type]] . . .
WithEvents (optional; Keyword)

A keyword that denotes the object variable, varname, can respond to events triggered from within the object to which it refers

varname (required; any)

The name of the variable, following Visual Basic naming conventions

subscripts (optional; Integer or Long)

Denotes varname as an array and specifies the number and extent of array dimensions

New (optional; Keyword)

Used to automatically create an instance of the object referred to by the object variable, varname

type (optional; 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 Private variable’s scope is limited to the module in which it is 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 you write other more common event handlers.

  • There is no limit to the number ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required