注册 登录
就爱编程论坛 返回首页

晴云孤魂的个人空间 http://bbs.waibc.com/?1 [收藏] [复制] [分享] [RSS]

日志

[点击图标 标记为星标记事] GetRef Function

已有 441 次阅读2012-7-22 07:29 |个人分类:资料收藏夹

out of 5 rated this helpful - Rate this topic

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>
Did you find this helpful?
Community Content Add
FAQ
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")




  • 1/26/2009
  • OxG
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


路过

鸡蛋

鲜花

握手

雷人
收藏 分享 分享到人人 转发到微博 举报

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册
验证问答 换一个 验证码 换一个

晴云孤魂's Blog|就爱编程搜帖|手机版|Archiver|就爱编程论坛     

GMT+8, 2025-7-1 14:06 , Processed in 0.072856 second(s), 25 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部