Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
Scripting
VBScript
 GetRef Function

  Switch on low bandwidth view
This page is specific to
.NET Framework 3.0

Other versions are also available for the following:
Visual Basic Scripting Edition
GetRef Function

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

Set object.eventname = GetRef(procname)
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.

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>
Community Content   What is Community Content?
Add new content RSS  Annotations
passing parameters to a sub or function pointed to by getref()      alfonsopilato   |   Edit   |   Show History

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

Does Not Work With Methods      OxG   |   Edit   |   Show History

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")




Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker