Skip to Content
VB & VBA in a Nutshell: The Language
book

VB & VBA in a Nutshell: The Language

by Paul Lomax
October 1998
Intermediate to advanced
656 pages
16h 10m
English
O'Reilly Media, Inc.
Content preview from VB & VBA in a Nutshell: The Language
Event Statement

Named Arguments

No

Syntax

Public Event eventName [(arglist)]

eventName

Use: Required

Data Type: String

The name of the event.

arglist

Optional; has the following syntax:

[ByVal | ByRef] varname[( )] [As type]

ByVal

Use: Optional

The argument is passed by value; that is, a local copy of the variable is assigned the value of the argument.

ByRef

Use: Optional

The argument is passed by reference; that is, the local variable is simply a reference to the argument being passed. All changes made to the local variable are reflected in the calling argument. ByRef is the default method of passing variables.

varname

Use: Required

The name of the local variable containing either the reference or value of the argument.

type

Use: Optional

The data type of the argument. Can be any data type.

Description

Defines a custom event that the object can raise at any time using the RaiseEvent statement.

Rules at a Glance

  • The event declaration must be Public so that it's visible outside the object module; it can't be declared as Friend or Private.

  • An Event statement can appear only in the Declarations section of an object module—that is, in a form or class module.

Example

The following snippet demonstrates how you can use an event to communicate a status message back to the client application. To take advantage of this functionality, the client must declare a reference to this class using the WithEvents keyword.

Public Event Status(Message As String) Private Function UpdateRecords() ...
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.
Start your free trial

You might also like

Absolute Beginner's Guide to VBA

Absolute Beginner's Guide to VBA

Paul McFedries
Visual Basic 2015 Unleashed

Visual Basic 2015 Unleashed

Alessandro Del Sole

Publisher Resources

ISBN: 1565923588Catalog PageErrata