Name
GetRef Function
Syntax
Set object.eventname
= GetRef(procname)
-
object
Use: Required
Data Subtype: String literal
Name of the object with which
eventname
is associated.-
eventname
Use: Required
Data Subtype: String literal
Name of the event to which the function is to be bound.
-
procname
Use: Required
Data Subtype: String literal
String containing the name of the Sub or Function procedure being associated with the event.
Return Value
The address of the procedure to execute when
object.eventname
is fired.
Description
Binds a particular procedure to an event. It specifies a particular procedure as the event handler that will be executed automatically whenever the event is fired.
Rules at a Glance
GetRef
allows you to bind a procedure to a DHTML (Dynamic HTML) event. This allows you to set events to specific pieces of code, making the code easier to maintain.You can bind to any of the events in the DHTML object model.
GetRef
works only with DHTML events; it does not respond to events in other VBScript-hosted environments such as Outlook forms, IIS, or WSH.
Example
<SCRIPT LANGUAGE="VBScript"> Function VarTestText( ) Dim varText varText = "This is a test" & vbCrLf varText = varText & "Test Continued" MsgBox varText End Function Set Window.Onload = GetRef("varTestText") </SCRIPT>
Programming Tips & Gotchas
Though GetRef
has no effect in defining an event
handler for non-DHTML events, it generates a runtime error only if
both object.eventname
and
procname
exist in the same script.
VBA/VBScript Differences ...
Get VBScript in a Nutshell 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.