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

Public Statement

Syntax

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

In a derived class definition, indicates that a variable overrides a similar variable in a base class

Shadows (optional; Keyword)

In a derived class definition, indicates that calls to derived class members that are made through a base class ignore the shadowed implementation

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; String literal)

The name of the variable, which must follow Visual Basic naming conventions

subscripts (optional; Numeric constant or literal)

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

New (optional; Keyword)

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

type (optional)

Data type of the variable varname

Description

Used at module level to declare a public variable and allocate the relevant storage space in memory.

A Public variable has both project-level scope — that is, it can be used by all procedures in all modules in the project — and, when used in a Class module, it can have scope outside the project.

The Public keyword also applies to procedures and class modules.

Rules at a Glance

  • The behavior of a Public variable depends on ...

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