Functions (VBScript)


Visual Basic Scripting Edition
GetRef Function

Returns a reference to a procedure that can be bound to an event.

Set object.eventname = GetRef(procname)
Arguments

object

Required. Name of the object with which event is associated.

event

Required. Name of the event to which the function is to be bound.

procname

Required. String containing the name of the Sub or Function procedure being associated with the event.

Remarks

The GetRef function allows you to connect a VBScript procedure (Function or Sub) to any available event on your DHTML (Dynamic HTML) pages. The DHTML object model provides information about what events are available for its various objects.

In other scripting and programming languages, the functionality provided by GetRef is referred to as a function pointer, that is, it points to the address of a procedure to be executed when the specified event occurs.

The following example illustrates the use of the GetRef function.

<SCRIPT LANGUAGE="VBScript">

Function GetRefTest()
   Dim Splash
   Splash = "GetRefTest Version 1.0"   & vbCrLf
   Splash = Splash & Chr(169) & " YourCompany 1999 "
   MsgBox Splash
End Function

Set Window.Onload = GetRef("GetRefTest")
</SCRIPT>
Requirements

Version 5

See Also

Reference



Community Content

alfonsopilato
passing parameters to a sub or function pointed to by getref()

Hi anyone out there who might be looking for this. I spent a bit of time figuring this out, and would like to share this info since I've gotten so much from the net, it's my chance to give back.

Some of you may already know this, but I'm no genius, so here it goes.

Consider this scenario. Now you may ask, why would you ever need to do this? Well, I never did need it until ... the need for it came about :-)))

My mistake was I was trying to get a reference to the function or sub including the parameters.. something like set a = getRef("somefunction('" & parameter1 & "')" .. but that failed miserably.

The solution follows...

call hub("specialA",param1,param2)

....

sub hub(dowhat,param1,param2)

'calls the appropriate sub based on parameters given

dim func

on error resume next 'here in case you haven't built the function you're about to reference in the line below..

set func = getRef("exampleSub_" & dowhat) ' first look for the sub or function by name only, in this case i'm looking for a sub or a function called "exampleSub_Speciala"

call func(param1,param2) 'here's where the magic happens

on error goto 0

end sub

'here's your sub that you're calling

sub exampleSub_specialA(param1,param2)

'do stuff here using param1 and param2 that were passed!

end sub


OxG
Does Not Work With Methods

In case anyone else spins their wheels like me, note a couple of things:

1) Needs Subroutine/Function name as string. Not very obvious...

Sub Fu
    MsgBox "Whatever"
End Sub

Set BadRef = GetRef ( Fu)
Set GoodRef = GetRef ( "Fu")


2) Won't work with class methods

Class Toe
Public Sub Fu
MsgBox "Howdy"
End Sub
End Class
'





















Set Kung = New ( Toe)
Set BadRef = GetRef ( "Kung.Fu")





Page view tracker