Name
GetRef Function
Syntax
GetRef(procname
)
procname
Use: Required
Data Type: String
Name of a sub or function
Return Value
A Long containing a reference to
procname.
Description
Returns a reference to a sub or function. This reference can be used for such purposes as binding to events or defining callback functions.
Rules at a Glance
GetRef can be used whenever a function or procedure reference is expected.
When using GetRef to define event handlers for events, the
Set
keyword is required. For example, the code required to bind the Window.OnLoad event to a procedure named ShowGreetingDialog is:Set Window.OnLoad = GetRef("ShowGreetingDialog")
Example
<HTML> <HEAD> <TITLE>The VBScript GetRef Function</TITLE> </HEAD> <BODY> <SCRIPT LANGUAGE="VBSCRIPT"> Set popWin = Window.CreatePopup( ) Set Window.Onload = GetRef("ShowPopup") Sub ShowPopup( ) Set popBody = popWin.Document.Body popBody.Style.BackgroundColor = "lightblue" popBody.Style.Border = "solid black" popBody.innerHTML = "Click outside <B>popup</B> to close." popWin.Show 100, 100, 220, 30, Document.body End Sub </SCRIPT> </BODY> </HTML>
Programming Tips and Gotchas
A common use of GetRef is to bind to DHTML events in Internet Explorer. You can use GetRef to bind to any of the events in the DHTML object model.
GetRef can be used to pass the address of a procedure to a routine that expects the address of a callback function as an argument.
VBA/VBScript Differences
The GetRef function is not supported by VBA. However, similar functionality is provided ...
Get VBScript in a Nutshell, 2nd Edition 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.