Name
GetRef Function
Syntax
Set object.eventname = GetRef(procname)-
object Use: Required
Data Subtype: String literal
Name of the object with which
eventnameis 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
GetRefallows 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.
GetRefworks 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 ...
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.
Read now
Unlock full access