GetRef Function
Returns a reference pointing to a process, which can be bound to an event.
Set object. eventname = GetRef (procname)
Parameters
Object
Required. Name of the object associated with the event.
Eventname
Required. The name of the event to bind to the function.
Procname
Required. This string contains the name of the Sub or Function process, which is associated with the event.
Description
The GetRef Function can be used to associate VBScript processes (functions or Sub) with any event available on the DHTML (Dynamic HTML) page. The DHTML Object Model provides information about various available events for different objects.
In other scripts and programming languages, the functions provided by GetRef are called function pointers, which point to the address of the process to be executed when a specified event occurs.
The following example shows how to use the GetRef function:
Copy codeThe Code is as follows: <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>
This is probably used to bind events. Because I do not know much about ASP events, I will not discuss the relationship between GetRef and events too much here. Here, we will only study the usefulness of GetRef in WEB development applications.
In PHP, PHP does not support pointers, so function pointers cannot be used. PHP supports the so-called "function variables" and can assign a function to a variable, which is similar to a function pointer.
Simple Example:
This can be done in PHP.Copy codeThe Code is as follows: <? Php
$ Funcname = "cutstr ";
Echo $ funcname ();
Function cutstr (){
Return "function ";
}
?>
With GetRef, ASP can also implement the following functions:
<%
Dim funcname
Funcname = "cutstr"
Response. Write (getref (funcname ))
Function cutstr ()
Cutstr = "function"
End function
%>
Practical application:
During background management projects, such as adding, deleting, and modifying news on the same page, we usually insert a hidden domain action in form, or the url parameter action is used to determine the operation step based on the value of the action. This is usually written as follows:
Select case request. querystring ("action ")
Case "add": 'Code segment to be operated ....
Case "modify": 'Code segment to operate ....
End select
Or use if else
The "function variable" can make the code more concise and clear. A complete example is provided, which is a common operation in the background. Modify, delete, and Add.
Available? Action = ××× to test the resultCopy codeThe Code is as follows: <%
Option explicit
Dim array_action
'Valid Module name
Array_action = array ("list", "add", "add_form", "modify", "modify_form", "del ")
'Output
Response. write (getref (action ))
'Check whether the parameter is valid
Function action ()
Dim str: str = request. querystring ("action ")
Action = array_action (0)
If arr_in (array_action, str) then action = str
End function
'Operation part ----------------------
Function list ()
List = "display list information"
End function
Function add ()
Add = "perform the add operation"
End function
Function add_form ()
Add_form = "show add form"
End function
Function modify ()
Modify = "perform the modification operation"
End function
'------------------------------
'Check whether the object exists in an array
Function arr_in (a, v)
Arr_in = false
Dim I
If isarray (a) then
For each I in
If I = v then: arr_in = true: exit for: end if
Next
End if
End function
%>
Many posts discuss ASP, PHP ,. NET, which one is strong? I personally think it is not a matter of language, but a matter of thinking. I understand the functional principles of websites and use the same language for writing, high efficiency, concise and clear code, it depends on your own level. Welcome to the discussion!